Skip to content

fix(api): add nil guard in volume mount response conversion - #3451

Open
chill-czar wants to merge 1 commit into
e2b-dev:mainfrom
chill-czar:fix/api-volume-mounts-nil-guard
Open

fix(api): add nil guard in volume mount response conversion#3451
chill-czar wants to merge 1 commit into
e2b-dev:mainfrom
chill-czar:fix/api-volume-mounts-nil-guard

Conversation

@chill-czar

Copy link
Copy Markdown
Contributor

Closes #3450

Summary

  • Add if item == nil { continue } guard in convertFromDBMountsToAPIMounts within packages/api/internal/handlers/sandboxes_list.go.
  • Add TestConvertFromDBMountsToAPIMounts unit tests in packages/api/internal/handlers/volume_util_test.go asserting nil items are skipped safely without panicking.

Why

When converting database volume mount configs to API response models, convertFromDBMountsToAPIMounts iterated over the slice items directly. If a nil pointer existed in the slice (e.g. from JSONB unmarshaling edge cases), dereferencing item.Name or item.Path triggered a nil pointer panic, crashing the active request handler goroutine for GET /sandboxes/{id} or GET /v2/sandboxes. Adding an explicit nil check guarantees handler safety.

Test Plan

  • Unit tests pass: go test -race -v -run TestConvertFromDBMountsToAPIMounts ./packages/api/internal/handlers/...
  • Verified nil slice element handling without panics
  • Formatted code cleanly: go fmt ./...
  • No regressions in volume utility handler tests

/cc @jakubno @dobrac @ValentaTomas @arkamar @tvi

@chill-czar

Copy link
Copy Markdown
Contributor Author

@codex

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Bravo.

Reviewed commit: e9031e3557

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@chill-czar
chill-czar force-pushed the fix/api-volume-mounts-nil-guard branch from e9031e3 to 6b510cb Compare August 4, 2026 14:59
@chill-czar

chill-czar commented Aug 4, 2026

Copy link
Copy Markdown
Contributor Author

Hi @jakubno @ben-fornefeld, could you please take a look at this PR when convenient?

Quick summary: Adds a nil element check in convertFromDBMountsToAPIMounts (sandboxes_list.go) to prevent nil-pointer panics when converting volume mount response objects. Includes unit test assertions in volume_util_test.go. Thanks!

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.

fix(api): add nil guard in volume mount response conversion

1 participant