fix: correct exit codes, download destination, and file walking - #29
Merged
Conversation
- 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Third item from the improvement backlog — a batch of small standalone bug fixes:
main()ignored the error returned bycmd.Execute(), so every failure exited with code 0. All commands are converted fromRun(+ scatteredlog.Fatalf) toRunE, errors propagate tomain, and the process exits 1.SilenceUsageis set so runtime errors print once instead of being followed by the full usage text. Thesouk gen/souk addsubcommands also no longer silently drop the errors their helpers already returned.download -odefault fixed. It defaulted to the installed binary's directory (e.g./usr/local/binfor a packaged install) while the help text claimed the current directory. It now defaults to., and the flag's help shows the real default.scanno longer panics on unreadable paths. Thefilepath.Walkcallback dereferenced itsFileInfowithout checking the walk error and ignoredWalk's return value; it now reusesutil.WalkAllFilesInDir, which handles both, and reports an empty walk as an error.util.ReadAllshort-read fixed. It issued a singleReadcall, which is not guaranteed to fill the buffer — large files could be silently truncated before hashing/uploading. Replaced withos.ReadFile.collectHashesreturns an error instead of callinglog.Fatalfdeep in a helper; new test covers the unreadable-file path.Test plan
go build ./... && go vet ./... && go test -race ./...passes locally.scan /nonexistent/pathprints a single error line and exits 1;download --helpshows(default ".").🤖 Generated with Claude Code