moq-mux: replace anyhow with thiserror#1495
Conversation
moq-mux is a library crate; per the workspace convention (thiserror for
libraries, anyhow for binaries) it shouldn't be exporting anyhow types
in its public API.
Each codec, container, and catalog format module now exports its own
Error enum (codec::{annexb,aac,opus,h264,h265,av1}::Error,
container::{fmp4,mkv,hls}::Error, catalog::msf::Error), flattened into
crate::Error via #[from]. Pure parsing functions (Config::parse,
Sps::parse, Avcc::parse, Avc1/Hvc1::transform, etc.) return their
module-local Result; importer/exporter structs return crate::Result so
they can mix codec errors with moq_net::Error and the other leaf
errors that flow through track operations.
Downstream:
- libmoq::Error::{InitFailed,DecodeFailed} now wrap Arc<moq_mux::Error>
instead of Arc<anyhow::Error>; added BufferNotConsumed for the one
ad-hoc anyhow!() site that didn't fit either bucket.
- moq-cli's PublishDecoder bridges moq_mux::Result into anyhow::Result
with explicit `?` since the binary still uses anyhow.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
WalkthroughThis PR removes the anyhow dependency and replaces untyped error handling with typed Error enums and Result aliases across moq-mux and consumers. It adds/expands crate- and module-level Error variants (including BufferNotConsumed and UnknownFormat), updates codec parsers and iterators (AAC, Opus, AV1, H.264, H.265, Annex-B), refactors container importers/exporters (fMP4, HLS, MKV), converts MSF catalog decoding, updates import/stream dispatchers, and adapts libmoq/moq-cli FFI/CLI surfaces to use moq_mux::Error. All mappings that used ensure!/bail!/context are converted to explicit Error variants and ok_or/map_err paths. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches✨ Simplify code
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
- Drop unused crate::Error::NotInitialized variant.
- Consolidate fmp4::Error::{NoMoof,MissingMoof} and {NoMoov,MissingMoov}
duplicates; both pairs described the same condition. Tighten the
remaining messages to match the Missing* sibling variants.
- Add Result<T> type aliases to container::{fmp4,mkv,hls} and
catalog::msf so all per-module error enums expose one. fmp4's Wire
Container impl falls back to std::result::Result because it needs the
two-arg form for Self::Error.
- Reorder libmoq::Error::ReturnCode so BufferNotConsumed sits next to
its numeric neighbors.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…drasekhar-da73a5 # Conflicts: # rs/libmoq/src/error.rs
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
rs/moq-mux/src/container/fmp4/mod.rs (1)
192-227:⚠️ Potential issue | 🟠 Major | ⚡ Quick winReturn an explicit bounds error instead of silently truncating decoded samples.
On Line 225,
decodereturnsOk(frames)when sample bounds exceedmdatlength. That silently accepts truncated/corrupt fragments. This should fail withError::SampleRangeOutOfBounds.Proposed fix
- if end > mdat_data.len() { - return Ok(frames); - } + if end > mdat_data.len() { + return Err(Error::SampleRangeOutOfBounds { + start: offset, + end, + len: mdat_data.len(), + }); + }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@rs/moq-mux/src/container/fmp4/mod.rs` around lines 192 - 227, The decode function currently returns Ok(frames) when a sample's end index exceeds mdat_data length, silently truncating; change this to return Err(Error::SampleRangeOutOfBounds) instead. In the loop inside decode (for trun in &traf.trun { for entry in &trun.entries { ... }}), replace the early return Ok(frames) when end > mdat_data.len() with an Err(...) using Error::SampleRangeOutOfBounds so malformed/corrupt fragments fail rather than being silently accepted; ensure the error is propagated from decode's Result<Vec<Frame>> signature.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@rs/moq-mux/src/container/fmp4/mod.rs`:
- Around line 192-227: The decode function currently returns Ok(frames) when a
sample's end index exceeds mdat_data length, silently truncating; change this to
return Err(Error::SampleRangeOutOfBounds) instead. In the loop inside decode
(for trun in &traf.trun { for entry in &trun.entries { ... }}), replace the
early return Ok(frames) when end > mdat_data.len() with an Err(...) using
Error::SampleRangeOutOfBounds so malformed/corrupt fragments fail rather than
being silently accepted; ensure the error is propagated from decode's
Result<Vec<Frame>> signature.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: a9a25ca6-6721-4931-9a1e-34b19c872c8f
⛔ Files ignored due to path filters (1)
Cargo.lockis excluded by!**/*.lock
📒 Files selected for processing (28)
rs/libmoq/src/error.rsrs/libmoq/src/publish.rsrs/moq-cli/src/publish.rsrs/moq-mux/Cargo.tomlrs/moq-mux/src/catalog/msf/consumer.rsrs/moq-mux/src/catalog/msf/mod.rsrs/moq-mux/src/codec/aac/import.rsrs/moq-mux/src/codec/aac/mod.rsrs/moq-mux/src/codec/annexb.rsrs/moq-mux/src/codec/av1/import.rsrs/moq-mux/src/codec/av1/mod.rsrs/moq-mux/src/codec/h264/import.rsrs/moq-mux/src/codec/h264/mod.rsrs/moq-mux/src/codec/h265/import.rsrs/moq-mux/src/codec/h265/mod.rsrs/moq-mux/src/codec/opus/import.rsrs/moq-mux/src/codec/opus/mod.rsrs/moq-mux/src/container/fmp4/export.rsrs/moq-mux/src/container/fmp4/import.rsrs/moq-mux/src/container/fmp4/mod.rsrs/moq-mux/src/container/hls/import.rsrs/moq-mux/src/container/hls/mod.rsrs/moq-mux/src/container/mkv/export.rsrs/moq-mux/src/container/mkv/import.rsrs/moq-mux/src/container/mkv/mod.rsrs/moq-mux/src/container/source.rsrs/moq-mux/src/error.rsrs/moq-mux/src/import.rs
💤 Files with no reviewable changes (1)
- rs/moq-mux/Cargo.toml
decode() previously returned Ok(frames) when a sample's end index exceeded mdat length, silently truncating the frame list. By the time decode() runs the full CMAF fragment is in hand, so a size mismatch is a corrupt-publisher signal rather than a streaming-truncation case worth tolerating. Returning Error::SampleRangeOutOfBounds lets the caller see the failure instead of receiving a misleading partial decode. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
Addressed the out-of-bounds-samples finding in 4737fac: |
Summary
Errorenum, flattened intocrate::Errorvia#[from]:codec::{annexb,aac,opus,h264,h265,av1}::Error,container::{fmp4,mkv,hls}::Error,catalog::msf::Error.Config::parse,Sps::parse,Avcc::parse,Avc1/Hvc1::transform, etc.) return their module-localResult. Importer/exporter struct methods returncrate::Resultbecause they interleave codec errors withmoq_net::Errorand the other leaf errors that flow through track operations.Downstream impact
libmoq::Error::{InitFailed,DecodeFailed}now wrapArc<moq_mux::Error>instead ofArc<anyhow::Error>. Added aBufferNotConsumedvariant for the one ad-hocanyhow!()site that didn't fit either bucket.moq-cli'sPublishDecoderkeepsanyhow::Resultand bridgesmoq_mux::Resultwith explicit?.Test plan
just check(cargo check + clippy -D warnings + fmt --check + doc + shear + sort) passescargo test -p moq-mux— 141 tests passcargo check --workspace --all-targets --exclude moq-gstbuilds (moq-gst is blocked by a local gstreamer install only, not by these changes)🤖 Generated with Claude Code
(Written by Claude)