Skip to content

Issue #29: Go refactor errors - #30

Merged
icahoon merged 5 commits into
mainfrom
feat/issue-29-go-refactor-errors
Sep 3, 2026
Merged

icahoon merged 5 commits into
mainfrom
feat/issue-29-go-refactor-errors

Conversation

@icahoon

@icahoon icahoon commented Sep 3, 2026

Copy link
Copy Markdown
Collaborator

Issue

Fixes #29

Summary

Adds an ErrorCode struct which provides a return code to os.Exit in Main.
Four manifest errors values have been defined

  • ErrUsage: for usage errors that can be corrected by the user
  • ErrIntenal: an internal error that is beyond the control of the user
  • ErrUnimplemented: an unimplemented feature
  • ErrUnknown: an unknown error has occurred

The entropylex command has been refactored to use these errors.

Key Changes

  • The OutputFile and InputFile functions have been moved to their on files, outputfile.go and inputfile.go. The accompanying unit tests have also been moved to outputfile_test.go and inputfile_test.go.
  • now using go1.27
  • enhances the "clean" make target

Design Rationale

The errors are properly isolated to the entropylex command, since they convey return result only relevant to the cli command.

Test Plan

  • updated unit tests where necessary
  • adds new unit test for ErrorCode

@icahoon

icahoon commented Sep 3, 2026

Copy link
Copy Markdown
Collaborator Author

Code review — PR #30 (feat/issue-29-go-refactor-errors)

High-effort review of the diff vs main. Six findings, most severe first.

🔴 Blocking / correctness

1. Test imports a bare uuid package that only exists locallyentropylex/cmd/entropylex/outputfile_test.go:7
The test imports "uuid", which resolves to a manually-added /usr/local/go/src/uuid. go.mod dropped github.com/google/uu id, so on any clean toolchain (CI included) the package won't compile — package uuid is not in std — and the whole package' s tests fail before running. Restore github.com/google/uuid.NewString().

2. Invalid -b now truncates the output file (data loss)entropylex/cmd/entropylex/command.go:95
Deleting the bit-depth flag Validator moved validation into the Action, which runs OutputFile() (create/truncate) before rejecting a bad -b. So entropylex -b 42 -o existing.dat --force truncates existing.dat to 0 bytes, then errors. Previou sly the flag validator rejected it at parse time, before any file was touched.

3. make clean wipes the shared module cacheMakefile:149
go clean -i -r -cache -testcache -modcache -fuzzcache — the -modcache blows away $GOMODCACHE for every Go project on t he machine, forcing a full re-download next build. -i -r also removes installed archives for all deps recursively.

🟡 Consistency / coverage

4. %s instead of %w breaks the error chainentropylex/cmd/entropylex/command.go:97
fmt.Errorf("%w: %s", ErrUsage, err) on the OutputFile path drops err from the unwrap chain, while the adjacent InputFile p ath (command.go:113) correctly uses %w: %w. Two otherwise-identical paths behave differently under errors.Is/As.

5. Usage errors no longer print command helpentropylex/cmd/entropylex/command.go:96
Removing DefaultShowRootCommandHelp means a usage error now prints only the one-line message from main.go, no usage guidan ce. Possibly intentional (tests were updated) — worth confirming the UX is intended.

6. Test_NewEntropyLex8 is an empty // TODO that always passesentropylex/cmd/entropylex/entropylex8_test.go:8
The three new ErrInternal-wrapping branches added to NewEntropyLex8 in this PR are untested; the placeholder reports succe ss without exercising any of them.

🤖 Generated with Claude Code

@icahoon

icahoon commented Sep 3, 2026

Copy link
Copy Markdown
Collaborator Author

Code review — PR #30 (feat/issue-29-go-refactor-errors)

High-effort review of the diff vs main. Six findings, most severe first.

🔴 Blocking / correctness

1. Test imports a bare uuid package that only exists locallyentropylex/cmd/entropylex/outputfile_test.go:7 The test imports "uuid", which resolves to a manually-added /usr/local/go/src/uuid. go.mod dropped github.com/google/uu id, so on any clean toolchain (CI included) the package won't compile — package uuid is not in std — and the whole package' s tests fail before running. Restore github.com/google/uuid.NewString().

This is incorrect. go1.27 now includes a uuid package.

2. Invalid -b now truncates the output file (data loss)entropylex/cmd/entropylex/command.go:95 Deleting the bit-depth flag Validator moved validation into the Action, which runs OutputFile() (create/truncate) before rejecting a bad -b. So entropylex -b 42 -o existing.dat --force truncates existing.dat to 0 bytes, then errors. Previou sly the flag validator rejected it at parse time, before any file was touched.

I'll fix this.

3. make clean wipes the shared module cacheMakefile:149 go clean -i -r -cache -testcache -modcache -fuzzcache — the -modcache blows away $GOMODCACHE for every Go project on t he machine, forcing a full re-download next build. -i -r also removes installed archives for all deps recursively.

I'm fine withe the entire module cache being destroyed.

🟡 Consistency / coverage

4. %s instead of %w breaks the error chainentropylex/cmd/entropylex/command.go:97 fmt.Errorf("%w: %s", ErrUsage, err) on the OutputFile path drops err from the unwrap chain, while the adjacent InputFile p ath (command.go:113) correctly uses %w: %w. Two otherwise-identical paths behave differently under errors.Is/As.

I'll fix this.

5. Usage errors no longer print command helpentropylex/cmd/entropylex/command.go:96 Removing DefaultShowRootCommandHelp means a usage error now prints only the one-line message from main.go, no usage guidan ce. Possibly intentional (tests were updated) — worth confirming the UX is intended.

This is intended.

6. Test_NewEntropyLex8 is an empty // TODO that always passesentropylex/cmd/entropylex/entropylex8_test.go:8 The three new ErrInternal-wrapping branches added to NewEntropyLex8 in this PR are untested; the placeholder reports succe ss without exercising any of them.

This is fine for now.

🤖 Generated with Claude Code

@XenonofArcticus XenonofArcticus left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Within my skill and effort, this looks reasonable.

@icahoon
icahoon merged commit 36a9f87 into main Sep 3, 2026
1 check passed
@icahoon
icahoon deleted the feat/issue-29-go-refactor-errors branch September 3, 2026 20:03
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.

Go: refactor errors

2 participants