📋 Pre-flight Checks
🔍 Problem Description
cmdExport calls fatal() on every failure path. That has two consequences:
- It cannot be tested. Any test that exercises a failure path kills the
test binary, so the error behaviour of export is effectively untested.
- It cannot be reused. No other command can call export and decide what to
do on failure, because the decision is hardcoded to "exit the process".
The same pattern makes the failure message less useful than it could be: a
failed write reports the OS error without saying which path it was writing to.
💡 Proposed Solution
Have cmdExport return (outFile string, err error) and let main decide.
The CLI keeps exactly the same observable behaviour — main calls fatal on
a returned error — but the function becomes testable and reusable, and the
write failure is wrapped with the target path.
This follows the error-handling convention the rest of the codebase already
uses for functions below the command layer.
📦 Affected Area
cmd/engram — cmdExport and its call site in main.
🔄 Alternatives Considered
- Leave it as is. Cheapest, but keeps export permanently untestable.
- Inject an exit function. More indirection than the problem warrants;
returning an error is the idiomatic Go answer.
📎 Additional Context
I have the change ready, including tests that exercise the failure paths,
which is what the current signature makes impossible.
Happy to open the PR once this is approved.
📋 Pre-flight Checks
status:approvedbefore a PR can be opened🔍 Problem Description
cmdExportcallsfatal()on every failure path. That has two consequences:test binary, so the error behaviour of export is effectively untested.
do on failure, because the decision is hardcoded to "exit the process".
The same pattern makes the failure message less useful than it could be: a
failed write reports the OS error without saying which path it was writing to.
💡 Proposed Solution
Have
cmdExportreturn(outFile string, err error)and letmaindecide.The CLI keeps exactly the same observable behaviour —
maincallsfatalona returned error — but the function becomes testable and reusable, and the
write failure is wrapped with the target path.
This follows the error-handling convention the rest of the codebase already
uses for functions below the command layer.
📦 Affected Area
cmd/engram—cmdExportand its call site inmain.🔄 Alternatives Considered
returning an error is the idiomatic Go answer.
📎 Additional Context
I have the change ready, including tests that exercise the failure paths,
which is what the current signature makes impossible.
Happy to open the PR once this is approved.