- Created docs/ directory for better organization - Moved 35 markdown files from root to docs/ - Includes all status reports, guides, and testing documentation Co-Authored-By: Warp <agent@warp.dev>
2.0 KiB
2.0 KiB
Bug Fix: Disk Discovery JSON Parsing Issue
Problem
The disk listing endpoint was returning 500 Internal Server Error with the error:
failed to parse lsblk output: json: cannot unmarshal number into Go struct field .blockdevices.size of type string
Root Cause
The lsblk -J command returns JSON where the size field is a number, but the Go struct expected it as a string. This caused a JSON unmarshaling error.
Solution
Updated the struct to accept size as interface{} and added type handling to parse both string and number formats.
Changes Made
File: backend/internal/storage/disk.go
-
Updated struct definition to accept
sizeasinterface{}:var lsblkOutput struct { BlockDevices []struct { Name string `json:"name"` Size interface{} `json:"size"` // Can be string or number Type string `json:"type"` } `json:"blockdevices"` } -
Updated size parsing logic to handle both string and number types:
// Parse size (can be string or number) var sizeBytes int64 switch v := device.Size.(type) { case string: if size, err := strconv.ParseInt(v, 10, 64); err == nil { sizeBytes = size } case float64: sizeBytes = int64(v) case int64: sizeBytes = v case int: sizeBytes = int64(v) } disk.SizeBytes = sizeBytes
Testing
After this fix, the disk listing endpoint should work correctly:
curl http://localhost:8080/api/v1/storage/disks \
-H "Authorization: Bearer $TOKEN"
Expected Response: 200 OK with a list of physical disks.
Impact
- ✅ Disk discovery now works correctly
- ✅ Handles both string and numeric size values from
lsblk - ✅ More robust parsing that works with different
lsblkversions - ✅ No breaking changes to API response format
Related Files
backend/internal/storage/disk.go- Disk discovery and parsing logic