Skip to content

Commit 1abe0ec

Browse files
nit on logs
1 parent decc121 commit 1abe0ec

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

packages/backend/src/env.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export const env = createEnv({
4343

4444
LOGTAIL_TOKEN: z.string().optional(),
4545
LOGTAIL_HOST: z.string().url().optional(),
46+
SOURCEBOT_LOG_LEVEL: z.enum(["info", "debug", "warn", "error"]).default("info"),
4647

4748
DATABASE_URL: z.string().url().default("postgresql://postgres:postgres@localhost:5432/postgres"),
4849
CONFIG_PATH: z.string().optional(),

packages/backend/src/git.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { CheckRepoActions, GitConfigScope, simpleGit, SimpleGitProgressEvent } from 'simple-git';
22
import { mkdir } from 'node:fs/promises';
3+
import { env } from './env.js';
34

45
type onProgressFn = (event: SimpleGitProgressEvent) => void;
56

@@ -26,10 +27,15 @@ export const cloneRepository = async (
2627
"--progress",
2728
]);
2829
} catch (error: unknown) {
29-
if (error instanceof Error) {
30-
throw new Error(`Failed to clone repository: ${error.message}`);
30+
const baseLog = `Failed to clone repository: ${path}`;
31+
32+
if (env.SOURCEBOT_LOG_LEVEL !== "debug") {
33+
// Avoid printing the remote URL (that may contain credentials) to logs by default.
34+
throw new Error(`${baseLog}. Set environment variable SOURCEBOT_LOG_LEVEL=debug to see the full error message.`);
35+
} else if (error instanceof Error) {
36+
throw new Error(`${baseLog}. Reason: ${error.message}`);
3137
} else {
32-
throw new Error(`Failed to clone repository: ${error}`);
38+
throw new Error(`${baseLog}. Error: ${error}`);
3339
}
3440
}
3541
};
@@ -53,10 +59,14 @@ export const fetchRepository = async (
5359
"--progress"
5460
]);
5561
} catch (error: unknown) {
56-
if (error instanceof Error) {
57-
throw new Error(`Failed to fetch repository ${path}: ${error.message}`);
62+
const baseLog = `Failed to fetch repository: ${path}`;
63+
if (env.SOURCEBOT_LOG_LEVEL !== "debug") {
64+
// Avoid printing the remote URL (that may contain credentials) to logs by default.
65+
throw new Error(`${baseLog}. Set environment variable SOURCEBOT_LOG_LEVEL=debug to see the full error message.`);
66+
} else if (error instanceof Error) {
67+
throw new Error(`${baseLog}. Reason: ${error.message}`);
5868
} else {
59-
throw new Error(`Failed to fetch repository ${path}: ${error}`);
69+
throw new Error(`${baseLog}. Error: ${error}`);
6070
}
6171
}
6272
}

0 commit comments

Comments
 (0)