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

Open Beginner friendly
#3,450 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
88/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Quiet
Tech stack
go
Domain
api, backend

Research direction

Start in packages/api/internal/handlers/sandboxes_list.go at convertFromDBMountsToAPIMounts, then review the related cases in packages/api/internal/handlers/volume_util_test.go. Run the handler tests and add coverage for a nil mount element. Done means sparse input no longer panics and nil entries are omitted from the API response.

Written by the indexing model from the issue text.

Description

Problem

In packages/api/internal/handlers/sandboxes_list.go, convertFromDBMountsToAPIMounts converts database volume mount slice items into API response structs (api.SandboxVolumeMount). If the input slice contains a nil element (e.g. unmarshaled from JSONB payloads containing sparse/null entries), accessing item.Name or item.Path triggers a nil pointer dereference panic, failing the active HTTP request goroutine for sandbox GET/LIST endpoints.

Root Cause

convertFromDBMountsToAPIMounts iterated directly over mounts without checking if item == nil.

Setting / Factor Current Value / State Intended / Expected
File / Component packages/api/internal/handlers/sandboxes_list.go:L346-L359 Defensive nil element guard
Behavior item.Name dereference panics on nil item Skip nil items safely

Reproduction Steps

  1. Invoke convertFromDBMountsToAPIMounts([]*dbtypes.SandboxVolumeMountConfig{nil}).
  2. Observed result: Nil pointer dereference panic.
  3. Expected result: Skips nil item, returns empty slice pointer.
mounts := []*dbtypes.SandboxVolumeMountConfig{nil}
res := convertFromDBMountsToAPIMounts(mounts) // panics on item.Name

Technical Context

  • Files affected: packages/api/internal/handlers/sandboxes_list.go, packages/api/internal/handlers/volume_util_test.go
  • Subsystem: Control Plane API
  • Impact: Low/Medium (Defensive nil safety)

Proposed Changes

# Change File(s) Affected Complexity
1 Add if item == nil { continue } guard in convertFromDBMountsToAPIMounts sandboxes_list.go Low
2 Add unit tests in volume_util_test.go volume_util_test.go Low
Dominant language
Go
Stars
1.6k
Forks
438
PR merge metrics
No merged PRs in 30d

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.

More from e2b-dev/runtime

All issues in e2b-dev/runtime

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.