Skip to content

Commit 82c41df

Browse files
Fix undefined projectRoot in npm-app logger initialization by deriving project root with getProjectRoot() and falling back to process.cwd() to avoid TypeError.
🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
1 parent e903da0 commit 82c41df

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

npm-app/src/utils/logger.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { format as stringFormat } from 'util'
55
import { AnalyticsEvent } from '@codebuff/common/constants/analytics-events'
66
import { pino } from 'pino'
77

8-
import { getCurrentChatDir } from '../project-files'
8+
import { getCurrentChatDir, getProjectRoot } from '../project-files'
99
import { flushAnalytics, logError, trackEvent } from './analytics'
1010

1111
export interface LoggerContext {
@@ -64,11 +64,20 @@ function sendAnalyticsAndLog(
6464
process.env.CODEBUFF_GITHUB_ACTIONS !== 'true' &&
6565
process.env.NEXT_PUBLIC_CB_ENVIRONMENT !== 'test'
6666
) {
67-
setLogPath(
67+
const projectRoot = getProjectRoot() || process.cwd()
68+
69+
const logTarget =
6870
process.env.NEXT_PUBLIC_CB_ENVIRONMENT === 'dev'
69-
? path.join(__dirname, '../../../debug', 'npm-app.log')
70-
: path.join(getCurrentChatDir(), 'log.jsonl'),
71-
)
71+
? path.join(projectRoot, 'debug', 'npm-app.log')
72+
: (() => {
73+
try {
74+
return path.join(getCurrentChatDir(), 'log.jsonl')
75+
} catch {
76+
return path.join(projectRoot, 'debug', 'npm-app.log')
77+
}
78+
})()
79+
80+
setLogPath(logTarget)
7281
}
7382

7483
const toTrack = {

0 commit comments

Comments
 (0)