You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: add timeout_type/timeoutType field to TimeoutException/TimeoutError
Fixes#463. Users can now distinguish between sandbox, request, and
execution timeouts by checking the type field instead of parsing error
messages.
Python SDK: TimeoutException gains a `timeout_type` attribute
(str | None) set to "sandbox_timeout", "request_timeout", or
"execution_timeout" at every construction site.
JS SDK: TimeoutError gains a readonly `timeoutType` property
(TimeoutType | undefined) with the same three values. A new
`TimeoutType` union type is exported from the package.
AI Disclosure: this PR was authored by Claude Opus 4.6 (an AI).
Copy file name to clipboardExpand all lines: packages/js-sdk/src/envd/rpc.ts
+10-6Lines changed: 10 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -26,14 +26,18 @@ export function handleRpcError(err: unknown): Error {
26
26
returnformatSandboxTimeoutError(err.message)
27
27
caseCode.Canceled:
28
28
returnnewTimeoutError(
29
-
`${err.message}: This error is likely due to exceeding 'requestTimeoutMs'. You can pass the request timeout value as an option when making the request.`
29
+
\`\${err.message}: This error is likely due to exceeding 'requestTimeoutMs'. You can pass the request timeout value as an option when making the request.\`,
30
+
undefined,
31
+
'request_timeout'
30
32
)
31
33
case Code.DeadlineExceeded:
32
34
return new TimeoutError(
33
-
`${err.message}: This error is likely due to exceeding 'timeoutMs' — the total time a long running request (like command execution or directory watch) can be active. It can be modified by passing 'timeoutMs' when making the request. Use '0' to disable the timeout.`
35
+
\`\${err.message}: This error is likely due to exceeding 'timeoutMs' — the total time a long running request (like command execution or directory watch) can be active. It can be modified by passing 'timeoutMs' when making the request. Use '0' to disable the timeout.\`,
`${message}: This error is likely due to sandbox timeout. You can modify the sandbox timeout by passing 'timeoutMs' when starting the sandbox or calling '.setTimeout' on the sandbox with the desired timeout.`
16
+
\`\${message}: This error is likely due to sandbox timeout. You can modify the sandbox timeout by passing 'timeoutMs' when starting the sandbox or calling '.setTimeout' on the sandbox with the desired timeout.\`,
17
+
undefined,
18
+
'sandbox_timeout'
5
19
)
6
20
}
7
21
@@ -30,11 +44,29 @@ export class SandboxError extends Error {
30
44
* The [deadline_exceeded] error type is caused by exceeding the timeout for command execution, watch, etc.
31
45
*
32
46
* The [unknown] error type is sometimes caused by the sandbox timeout when the request is not processed correctly.
47
+
*
48
+
* Use the {@link timeoutType} property to determine which kind of timeout occurred
49
+
* without having to parse the error message.
33
50
*/
34
51
export class TimeoutError extends SandboxError {
35
-
constructor(message: string,stackTrace?: string){
52
+
/**
53
+
* Indicates which kind of timeout occurred.
54
+
*
55
+
* - \`"sandbox_timeout"\` – the sandbox itself timed out (idle / max lifetime).
56
+
* - \`"request_timeout"\` – a single HTTP / RPC request exceeded its deadline.
57
+
* - \`"execution_timeout"\` – a long-running operation (process, watch, etc.) exceeded its allowed duration.
f"{e.message}: This error is likely due to exceeding 'request_timeout'. You can pass the request timeout value as an option when making the request."
36
+
f"{e.message}: This error is likely due to exceeding 'request_timeout'. You can pass the request timeout value as an option when making the request.",
37
+
timeout_type="request_timeout",
37
38
)
38
39
elife.status==Code.deadline_exceeded:
39
40
returnTimeoutException(
40
-
f"{e.message}: This error is likely due to exceeding 'timeout' — the total time a long running request (like process or directory watch) can be active. It can be modified by passing 'timeout' when making the request. Use '0' to disable the timeout."
41
+
f"{e.message}: This error is likely due to exceeding 'timeout' — the total time a long running request (like process or directory watch) can be active. It can be modified by passing 'timeout' when making the request. Use '0' to disable the timeout.",
f"{message}: This error is likely due to sandbox timeout. You can modify the sandbox timeout by passing 'timeout' when starting the sandbox or calling '.set_timeout' on the sandbox with the desired timeout."
3
+
f"{message}: This error is likely due to sandbox timeout. You can modify the sandbox timeout by passing 'timeout' when starting the sandbox or calling '.set_timeout' on the sandbox with the desired timeout.",
4
+
timeout_type="sandbox_timeout",
4
5
)
5
6
6
7
7
8
defformat_request_timeout_error() ->Exception:
8
9
returnTimeoutException(
9
10
"Request timed out — the 'request_timeout' option can be used to increase this timeout",
11
+
timeout_type="request_timeout",
10
12
)
11
13
12
14
13
15
defformat_execution_timeout_error() ->Exception:
14
16
returnTimeoutException(
15
17
"Execution timed out — the 'timeout' option can be used to increase this timeout",
18
+
timeout_type="execution_timeout",
16
19
)
17
20
18
21
@@ -34,9 +37,17 @@ class TimeoutException(SandboxException):
34
37
The `canceled` exception type is caused by exceeding request timeout.\n
35
38
The `deadline_exceeded` exception type is caused by exceeding the timeout for process, watch, etc.\n
36
39
The `unknown` exception type is sometimes caused by the sandbox timeout when the request is not processed correctly.\n
40
+
41
+
The ``timeout_type`` attribute indicates which kind of timeout occurred:
42
+
43
+
- ``"sandbox_timeout"`` – the sandbox itself timed out (idle / max lifetime).
44
+
- ``"request_timeout"`` – a single HTTP / RPC request exceeded its deadline.
45
+
- ``"execution_timeout"`` – a long-running operation (process, watch, …) exceeded its allowed duration.
0 commit comments