# 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` 1. **Updated struct definition** to accept `size` as `interface{}`: ```go var lsblkOutput struct { BlockDevices []struct { Name string `json:"name"` Size interface{} `json:"size"` // Can be string or number Type string `json:"type"` } `json:"blockdevices"` } ``` 2. **Updated size parsing logic** to handle both string and number types: ```go // 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: ```bash 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 `lsblk` versions - ✅ No breaking changes to API response format ## Related Files - `backend/internal/storage/disk.go` - Disk discovery and parsing logic