Skip to content

cmdExport exits the process on every failure, so it cannot be tested or reused #727

Description

@Rene-Kuhm

📋 Pre-flight Checks

  • I have searched existing issues and this is not a duplicate
  • I understand this issue needs status:approved before a PR can be opened

🔍 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/engramcmdExport 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions