Skip to content

Commit 54dd1bc

Browse files
committed
fix(size): display results even when listing errors occur
Previously, any error during directory enumeration (e.g., a subdirectory being deleted mid-operation) would cause the size command to exit without displaying results, even though partial counts were successfully computed. Remove the early return on error and ensure results are always printed before returning. The error is still returned for proper exit code handling, so scripts checking exit status continue to work correctly. For JSON output, if both Count and JSON encoding fail, the Count error takes priority as it's more meaningful to the user. Signed-off-by: Anagh Kumar Baranwal <[email protected]>
1 parent 51b197c commit 54dd1bc

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

cmd/size/size.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,19 @@ of the size command.`,
5858
}
5959

6060
results.Count, results.Bytes, results.Sizeless, err = operations.Count(context.Background(), fsrc)
61-
if err != nil {
62-
return err
63-
}
61+
// Don't return early on error - always show results
6462
if results.Sizeless > 0 {
6563
fs.Logf(fsrc, "Size may be underestimated due to %d objects with unknown size", results.Sizeless)
6664
}
6765
if jsonOutput {
68-
return json.NewEncoder(os.Stdout).Encode(results)
66+
encErr := json.NewEncoder(os.Stdout).Encode(results)
67+
if err != nil {
68+
if encErr != nil {
69+
fs.Logf(fsrc, "JSON output may be incomplete or corrupted: %v", encErr)
70+
}
71+
return err
72+
}
73+
return encErr
6974
}
7075
count := strconv.FormatInt(results.Count, 10)
7176
countSuffix := fs.CountSuffix(results.Count).String()
@@ -78,7 +83,7 @@ of the size command.`,
7883
if results.Sizeless > 0 {
7984
operations.SyncPrintf("Total objects with unknown size: %s (%d)\n", fs.CountSuffix(results.Sizeless), results.Sizeless)
8085
}
81-
return nil
86+
return err
8287
})
8388
},
8489
}

0 commit comments

Comments
 (0)