e2b-dev / e2b-dev/E2B

files.read / volume.read return None for an unrecognized format instead of raising

Open
#1,823 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug sdk
Dominant language
Python
Stars
13.9k
Forks
1k
Avg merge
1d 20h
Merged PRs (30d)
70

Description

format dispatch in read() has no fallback branch, so a value outside the union silently returns None (Python) rather than the file contents or an error.

Verified on staging with a real sandbox:

format='text'   -> str: 'hello'
format='bytes'  -> bytearray: bytearray(b'hello')
format='Text'   -> NoneType: None      # falls through every branch
format='txt'    -> NoneType: None

The dispatch is if format == "text": ... elif format == "bytes": ... with no else, so control falls off the end of the function after the request has already succeeded. The caller gets None where content should be, with no exception and nothing to indicate the argument was wrong.

Affected (both Python mirrors, and the JS equivalents):

  • packages/python-sdk/e2b/sandbox_sync/filesystem/filesystem.pyread()
  • packages/python-sdk/e2b/sandbox_async/filesystem/filesystem.pyread()
  • packages/python-sdk/e2b/volume/volume_sync.py / volume_async.pyread()
  • packages/js-sdk/src/volume/index.ts — the fall-through is marked by a // format === 'blob' comment, so an unrecognized value silently returns a Blob rather than the requested shape
  • packages/js-sdk/src/sandbox/filesystem/index.ts — same shape

Literal / the TS union catch this for typed callers; it reaches anyone passing the value through from config, a CLI flag, or plain JS.

Suggested fix: an else: raise InvalidArgumentException(...) / throw new InvalidArgumentError(...) naming the valid formats, matching GitResetMode and GitConfigScope, which already validate their literal domains in both SDKs. Ideally before the request is issued rather than after, so a bad argument doesn't cost a round trip.

Related: the same class on onTimeout / onResume, where the value is coerced to a boolean before the request is built — being fixed in #1822. Those two are more severe (a mistyped on_timeout deletes the sandbox at timeout); this one is a wrong return value rather than data loss, which is why it's split out.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with read() in the four Python files and the TypeScript entry points in packages/js-sdk/src/volume/index.ts and packages/js-sdk/src/sandbox/filesystem/index.ts. Compare literal validation in GitResetMode and GitConfigScope. Done means unrecognized formats are rejected before the request in every listed implementation, while valid text, bytes, and blob behavior remains intact.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, typescript
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
70/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.