Skip to content

fix: handle invalid status codes gracefully in error handler#1167

Merged
dobrac merged 2 commits into
mainfrom
dobrac/status-code-0-error
Feb 26, 2026
Merged

fix: handle invalid status codes gracefully in error handler#1167
dobrac merged 2 commits into
mainfrom
dobrac/status-code-0-error

Conversation

@dobrac
Copy link
Copy Markdown
Contributor

@dobrac dobrac commented Feb 26, 2026

Summary

Prevents the CLI from crashing when the API returns an error without a standard HTTP status code (e.g., network failures, timeouts, empty responses). Instead of throwing on status code 0, we now fall back to 'unknown error' while preserving the actual API error message.

Changes

  • Modified error handler to use status.message[code] map lookup instead of calling status(code) which throws on invalid codes
  • Added comprehensive tests covering status code 0, missing codes, and valid status codes

Note

Low Risk
Low risk: small change to error-message derivation plus unit tests; behavior only changes for unknown/invalid status codes (e.g., 0) to avoid throwing inside the handler.

Overview
Prevents the CLI error handler from crashing when the API returns a missing/invalid HTTP status code by replacing statuses(code) with a safe lookup via status.message[code] and falling back to unknown error.

Adds vitest coverage for no-error responses, known codes, code 0/missing codes, and a non-hardcoded valid code (e.g., 502), and includes a patch changeset for @e2b/cli.

Written by Cursor Bugbot for commit a43504f. This will update automatically on new commits. Configure here.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Feb 26, 2026

🦋 Changeset detected

Latest commit: a43504f

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

This PR includes changesets to release 1 package
Name Type
@e2b/cli 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

@dobrac dobrac added the bug Something isn't working label Feb 26, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Feb 26, 2026

Package Artifacts

Built from 7749c45. Download artifacts from this workflow run.

JS SDK (e2b@2.13.1-dobrac-status-code-0-error.0):

npm install ./e2b-2.13.1-dobrac-status-code-0-error.0.tgz

CLI (@e2b/cli@2.7.3-dobrac-status-code-0-error.0):

npm install ./e2b-cli-2.7.3-dobrac-status-code-0-error.0.tgz

Python SDK (e2b==2.14.0+dobrac-status-code-0-error):

pip install ./e2b-2.14.0+dobrac.status.code.0.error-py3-none-any.whl

Prevent crashes when API errors lack a proper HTTP status code (e.g., network
failures, empty responses). Instead of throwing on status code 0, we now fall
back to 'unknown error' while preserving the actual API error message. Uses
status.message map lookup instead of calling the status() function.

Includes tests covering invalid codes, missing codes, and known status codes.
@dobrac dobrac force-pushed the dobrac/status-code-0-error branch from 3bc1331 to a43504f Compare February 26, 2026 19:25
@dobrac dobrac marked this pull request as ready for review February 26, 2026 19:46
Copy link
Copy Markdown
Contributor

@matthewlouisbrockman matthewlouisbrockman left a comment

Choose a reason for hiding this comment

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

looks good.

@dobrac dobrac merged commit b989b29 into main Feb 26, 2026
23 checks passed
@dobrac dobrac deleted the dobrac/status-code-0-error branch February 26, 2026 19:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants