Skip to content

Adopt a consistent error-handling strategy across encode, decode, I/O, and CLI #28

Description

@audexdev

Summary

Error reporting differs at every layer of the pipeline — bool (dropping the reason), thrown std::runtime_error, thrown std::invalid_argument, and a status-enum-plus-string. This makes failures hard to surface uniformly and, for the block decoder, discards the reason a malformed stream was rejected.

Affected areas

  • src/codec/block/decoder.cpp
  • src/codec/lac/decoder.cpp
  • src/codec/lac/encoder.cpp
  • src/io/wav_io.cpp
  • src/main.cpp

Problem details

  • Block::Decoder::decode_into returns plain bool on every rejection, discarding which check failed — debug builds rely on LAC_DEBUG_* logging to recover any context.
  • LAC::Decoder::decode throws std::runtime_error with "[decode-error] ..." strings (decoder.cpp:26-33).
  • LAC::Encoder::encode throws std::invalid_argument (encoder.cpp:221-242).
  • read_wav / write_wav return bool (wav_io.cpp).
  • The CLI fast decode path returns a FastDecodeStatus enum plus an out-param std::string error (main.cpp:74-78,183-430).

The repo's stated direction is to "reject malformed input cleanly" and add malformed-input regression tests; a bool that loses the reason makes those tests assert only pass/fail and makes diagnostics depend on debug-only logging.

This is related to #7, which asks for consistent decode-time rejection of non-canonical metadata. This issue is the broader design question: one error/result strategy across encode, decode, I/O, and CLI.

Acceptance criteria

  • A single, documented error-reporting convention is chosen for the codec (e.g. a small Result/status type carrying a reason, or a consistent exception policy at the public boundary).
  • The block decoder can report why a stream was rejected without relying on NDEBUG-gated logging.
  • Container and block decode layers report failures consistently (aligns with Reject non-canonical LAC and block metadata during decode #7).
  • Malformed-input tests can assert on the specific rejection reason.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthardeningInput validation and robustness hardening

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions