Skip to content

Commit af0d488

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 5c53b97 commit af0d488

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

cmd/size/size.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,16 @@ 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+
return err
69+
}
70+
return encErr
6971
}
7072
count := strconv.FormatInt(results.Count, 10)
7173
countSuffix := fs.CountSuffix(results.Count).String()
@@ -78,7 +80,7 @@ of the size command.`,
7880
if results.Sizeless > 0 {
7981
operations.SyncPrintf("Total objects with unknown size: %s (%d)\n", fs.CountSuffix(results.Sizeless), results.Sizeless)
8082
}
81-
return nil
83+
return err
8284
})
8385
},
8486
}

0 commit comments

Comments
 (0)