Skip to content

Commit d1c0471

Browse files
committed
feat: 增强错误处理,添加沙盒生命周期提示信息的检查
1 parent 551efae commit d1c0471

1 file changed

Lines changed: 23 additions & 12 deletions

File tree

src/commands/sandbox/connect.ts

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,29 @@ export const connectCommand = new commander.Command('connect')
2222
// We explicitly call exit because the sandbox is keeping the program alive.
2323
// We also don't want to call sandbox.close because that would disconnect other users from the edit session.
2424
process.exit(0)
25-
} catch (err: any) {
26-
console.error(err)
27-
const message =
28-
typeof err?.message === 'string' ? err.message : String(err)
29-
if (/unknown[_ ]error/i.test(message)) {
30-
console.error(
31-
'Connection closed, it might be because the sandbox has reached the end of its lifecycle.'
32-
)
33-
}
34-
process.exit(1)
35-
}
36-
})
25+
} catch (err: any) {
26+
console.error(err)
27+
const message =
28+
typeof err?.message === 'string' ? err.message : String(err)
29+
if (shouldShowLifecycleHint(message)) {
30+
console.error(
31+
'Connection closed, it might be because the sandbox has reached the end of its lifecycle.'
32+
)
33+
}
34+
process.exit(1)
35+
}
36+
})
37+
38+
function shouldShowLifecycleHint(message: string): boolean {
39+
// Observed examples:
40+
// - "unknown_error"
41+
// - "Unknown error"
42+
// - "2: [unknown] terminated" (gRPC code 2 = UNKNOWN)
43+
return (
44+
/unknown[_ ]error/i.test(message) ||
45+
(/\[unknown\]/i.test(message) && /\bterminated\b/i.test(message))
46+
)
47+
}
3748

3849
async function connectToSandbox({
3950
apiKey,

0 commit comments

Comments
 (0)