Skip to content

Commit cd9d48f

Browse files
grichaclaude
andcommitted
Add error handling for runInit in container entrypoint
Addresses Sentry review feedback on PR #34. If runInit() throws (e.g., git clone fails), the container would crash and restart infinitely, preventing SSH access for debugging. Now initialization failures are caught and logged as non-fatal, allowing the SSH daemon to start so users can connect and debug. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 590faa7 commit cd9d48f

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

perry/internal/src/commands/entrypoint.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@ export const runEntrypoint = async () => {
2020
return;
2121
}
2222
console.log("[entrypoint] Running workspace initialization...");
23-
await runInit();
23+
try {
24+
await runInit();
25+
} catch (error) {
26+
console.log(`[entrypoint] Initialization failed (non-fatal): ${(error as Error).message}`);
27+
console.log("[entrypoint] SSH will still start - connect to debug the issue");
28+
}
2429
console.log("[entrypoint] Starting SSH daemon...");
2530
await startSshd();
2631
void monitorServices();

perry/internal/src/commands/init.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,15 @@ const cloneRepository = async (
8383
return;
8484
}
8585

86+
const repoName = repoUrl.replace(/\/+$/, "").split("/").pop() ?? "repo";
87+
const cleanRepoName = repoName.replace(/\.git$/, "");
88+
const repoPath = path.join(workspaceHome, cleanRepoName);
89+
if (await pathExists(repoPath)) {
90+
console.log(`Repository directory '${cleanRepoName}' already exists. Skipping clone.`);
91+
await configureGitSshKey(workspaceHome, repoPath, runtimeConfig?.ssh?.selectedKey ?? "");
92+
return;
93+
}
94+
8695
console.log("=== Configuration Debug Info ===");
8796
console.log(`Repository URL: ${repoUrl}`);
8897
await logRuntimeConfigContents(runtimeConfigPath);
@@ -143,9 +152,6 @@ const cloneRepository = async (
143152
}
144153
console.log("Repository clone completed.");
145154

146-
const repoName = repoUrl.replace(/\/+$/, "").split("/").pop() ?? "repo";
147-
const cleanRepoName = repoName.replace(/\.git$/, "");
148-
const repoPath = path.join(workspaceHome, cleanRepoName);
149155
if (await pathExists(repoPath)) {
150156
await configureGitSshKey(workspaceHome, repoPath, selectedKey);
151157
}

0 commit comments

Comments
 (0)