Skip to content

fix: correct exit codes, download destination, and file walking - #29

Merged
ayoubfaouzi merged 1 commit into
mainfrom
fix/cli-bugs
Aug 3, 2026
Merged

fix: correct exit codes, download destination, and file walking#29
ayoubfaouzi merged 1 commit into
mainfrom
fix/cli-bugs

Conversation

@ayoubfaouzi

Copy link
Copy Markdown
Member

Summary

Third item from the improvement backlog — a batch of small standalone bug fixes:

  • Failures now exit non-zero. main() ignored the error returned by cmd.Execute(), so every failure exited with code 0. All commands are converted from Run (+ scattered log.Fatalf) to RunE, errors propagate to main, and the process exits 1. SilenceUsage is set so runtime errors print once instead of being followed by the full usage text. The souk gen/souk add subcommands also no longer silently drop the errors their helpers already returned.
  • download -o default fixed. It defaulted to the installed binary's directory (e.g. /usr/local/bin for a packaged install) while the help text claimed the current directory. It now defaults to ., and the flag's help shows the real default.
  • scan no longer panics on unreadable paths. The filepath.Walk callback dereferenced its FileInfo without checking the walk error and ignored Walk's return value; it now reuses util.WalkAllFilesInDir, which handles both, and reports an empty walk as an error.
  • util.ReadAll short-read fixed. It issued a single Read call, which is not guaranteed to fill the buffer — large files could be silently truncated before hashing/uploading. Replaced with os.ReadFile.
  • collectHashes returns an error instead of calling log.Fatalf deep in a helper; new test covers the unreadable-file path.

Test plan

  • go build ./... && go vet ./... && go test -race ./... passes locally.
  • Manually verified: scan /nonexistent/path prints a single error line and exits 1; download --help shows (default ".").

🤖 Generated with Claude Code

- main() ignored Execute()'s error, so every failure exited 0; commands
  also used Run and log.Fatalf inconsistently. Convert all commands to
  RunE so errors propagate and the process exits 1, and silence cobra's
  usage dump on runtime errors.
- The download command defaulted its output directory to the directory
  of the installed binary while documenting the current directory; it
  now defaults to ".".
- The scan command's filepath.Walk callback dereferenced the FileInfo
  without checking the walk error, panicking on unreadable entries, and
  ignored Walk's return value. Reuse util.WalkAllFilesInDir which
  handles both.
- util.ReadAll issued a single Read call that is not guaranteed to fill
  the buffer, silently truncating large files; replace with os.ReadFile.
@ayoubfaouzi
ayoubfaouzi merged commit 481f805 into main Aug 3, 2026
3 checks passed
@ayoubfaouzi
ayoubfaouzi deleted the fix/cli-bugs branch August 3, 2026 13:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant