fix(api): add nil guard in volume mount response conversion
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 1.6k
- Forks
- 438
- PR merge metrics
- No merged PRs in 30d
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
- Invoke
convertFromDBMountsToAPIMounts([]*dbtypes.SandboxVolumeMountConfig{nil}). - Observed result: Nil pointer dereference panic.
- Expected result: Skips
nilitem, 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 |
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
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.
Assessment
- Tech stack
- go
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 88/100