Skip to content

fix(python-sdk): don't crash the build error path on a non-numeric reason.step - #1802

Open
nblintao wants to merge 2 commits into
e2b-dev:mainfrom
nblintao:fix/tolerate-non-numeric-build-step
Open

fix(python-sdk): don't crash the build error path on a non-numeric reason.step#1802
nblintao wants to merge 2 commits into
e2b-dev:mainfrom
nblintao:fix/tolerate-non-numeric-build-step

Conversation

@nblintao

@nblintao nblintao commented Sep 4, 2026

Copy link
Copy Markdown

Problem

On a failed template build, get_build_step_index (packages/python-sdk/e2b/template/utils.py) assumes reason.step is "base", "finalize", or a numeric string — int(step) has no fallback, and the call sites in template_sync/build_api.py / template_async/build_api.py don't catch. Any other value raises ValueError from inside the error path, masking the real BuildException the user should have seen.

Non-numeric values occur in practice:

  • e2b Cloud itself fills step with the literal strings "optimize" and "resize-disk" when those phases fail (e2b-dev/infra, packages/orchestrator/pkg/template/build/phases/{optimize,ensurefreedisk}/builder.goUnwrapUserError passes StepType through verbatim) — so the crash is reachable against the official backend, not only third-party ones.
  • The OpenAPI spec leaves the field an unconstrained string (BuildStatusReason.step: "Step that failed"), so nothing constrains it to be numeric.

The JS SDK already degrades gracefully here (Number(step)NaN → no traceback, error still thrown); this brings the Python SDK to parity.

Change

  • get_build_step_index returns Optional[int]: non-numeric, non-sentinel steps map to None ("no matching local stack trace") instead of raising.
  • Both call sites guard None and negative indices, so the BuildException is raised without a local traceback rather than being masked.
  • Unit tests for all four cases (base / finalize / numeric / non-numeric).

🤖 Generated with Claude Code

@cla-bot

cla-bot Bot commented Sep 4, 2026

Copy link
Copy Markdown

We require contributors to sign our Contributor License Agreement, and we don't have @nblintao on file. You can sign our CLA at https://e2b.dev/docs/cla . Once you've signed, post a comment here that says '@cla-bot check'

@changeset-bot

changeset-bot Bot commented Sep 4, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 9f88c45

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@e2b/python-sdk Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TASTE.md review: checked T-1/T-2 (sync/async parity — both build_api.py mirrors updated identically), T-42/T-62 (build error path still raises BuildException and threads the local traceback), T-71 (reST docstring updated for the new None return). No violations found in the changed lines; the internal helper's Optional[int] return and the is not None and 0 <= idx < len guard are the compliant form.

Non-blocking parity note (not a changed line): the JS twin getBuildStepIndex in packages/js-sdk/src/template/utils.ts returns Number(step)NaN for the same inputs, which happens to index to undefined rather than crash, so behavior matches — but its @returns still claims an index is always returned. Worth aligning the JSDoc (T-1) in a follow-up.

…ason.step

get_build_step_index hard-codes that reason.step is "base", "finalize",
or a numeric string, and int(step) has no fallback — any other value
raises ValueError from inside the error path, masking the real
BuildException. Such values occur in practice: e2b Cloud's own optimize
and resize-disk phases fill step with those literal strings, and
E2B-compatible backends have shipped instruction text there (the spec
leaves the field an unconstrained string).

A step with no usable index now maps to None and the build error is
raised without a local traceback, matching the JS SDK's behavior. Also
bounds-check negative indices at both call sites.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@nblintao
nblintao force-pushed the fix/tolerate-non-numeric-build-step branch from b7964e0 to 6ca3017 Compare September 4, 2026 16:17
@cla-bot

cla-bot Bot commented Sep 4, 2026

Copy link
Copy Markdown

We require contributors to sign our Contributor License Agreement, and we don't have @nblintao on file. You can sign our CLA at https://e2b.dev/docs/cla . Once you've signed, post a comment here that says '@cla-bot check'

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@cla-bot

cla-bot Bot commented Sep 4, 2026

Copy link
Copy Markdown

We require contributors to sign our Contributor License Agreement, and we don't have @nblintao on file. You can sign our CLA at https://e2b.dev/docs/cla . Once you've signed, post a comment here that says '@cla-bot check'

@nblintao

nblintao commented Sep 4, 2026

Copy link
Copy Markdown
Author

@cla-bot check

@cla-bot cla-bot Bot added the cla-signed label Sep 4, 2026
@cla-bot

cla-bot Bot commented Sep 4, 2026

Copy link
Copy Markdown

The cla-bot has been summoned, and re-checked this pull request!

@nblintao
nblintao marked this pull request as ready for review September 4, 2026 16:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant