-
Notifications
You must be signed in to change notification settings - Fork 13
add strict mode feature, enable on test #99
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
WalkthroughThe pull request introduces a strict mode feature to mp4-atom. The mode can be enabled through a new "strict" Cargo feature flag or by setting the MP4ATOM_STRICT environment variable. When strict mode is active, unknown boxes during parsing are treated as errors and cause parsing to fail. Without strict mode, unknown boxes generate warnings and parsing continues. The changes include updating documentation, adding the feature flag to the manifest, exporting the environment variable in the justfile, and modifying error handling logic to conditionally return errors based on strict mode settings. 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (3)
README.md (1)
105-115: Doc nits: feature naming + env var semantics should match implementation.
- Line 105: “
bytesfeatures” → “bytesfeature”.- Lines 109-110: since code treats “env var is present” as strict, consider clarifying “set
MP4ATOM_STRICT(e.g. to1)” to avoid implying it parses truthy/falsey values.Proposed doc tweak
-There's also the `bytes` features which enables encoding for `Bytes` and `BytesMut` from the `bytes` crate, often used with tokio. +There's also the `bytes` feature which enables encoding for `Bytes` and `BytesMut` from the `bytes` crate, often used with tokio. Enable using the `strict` feature, or by setting the `MP4ATOM_STRICT` environment variable. +For example: `MP4ATOM_STRICT=1`.src/error.rs (1)
72-80: Optional: Consider usingvar_os()for cleaner env handling.The strict-mode logic is correct. If you add tests for
MP4ATOM_STRICTenvironment variable mutation, usevar_os("MP4ATOM_STRICT").is_some()instead ofvar(...).is_ok()to avoid UTF-8 validation and to more clearly express intent (presence enables strict, not a specific value). Extract this to a local variable to avoid repeated evaluation:pub(crate) fn decode_unknown(atom: &Any, parent: FourCC) -> Result<()> { - if std::env::var("MP4ATOM_STRICT").is_ok() || cfg!(feature = "strict") { + let strict = cfg!(feature = "strict") || std::env::var_os("MP4ATOM_STRICT").is_some(); + if strict { tracing::error!(kind = %atom.kind(), parent = %parent, "unexpected box"); return Err(Error::UnexpectedBox(atom.kind())); } else { tracing::warn!(kind = %atom.kind(), parent = %parent, "unexpected box"); } Ok(()) }justfile (1)
5-8: MP4ATOM_STRICT is a top-level export affecting all recipes, but only has runtime impact ontest. The environment variable controls strict parsing behavior indecode_unknown()(src/error.rs), turning warnings into hard errors. Sincecargo check,cargo clippy, andcargo fmtare static analysis tools that don't execute decode logic, the export doesn't functionally affect thecheckandfixrecipes. However, for clarity and to align with the documented use case ("useful... when testing mp4-atom itself"), consider scopingMP4ATOM_STRICTto only thetestrecipe:Scope MP4ATOM_STRICT to test recipe
export RUST_BACKTRACE := "1" export RUST_LOG := "info" -export MP4ATOM_STRICT := "1" # Run any CI tests test: + MP4ATOM_STRICT=1 cargo test --all-targets - cargo test --all-targets
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
Cargo.tomlREADME.mdjustfilesrc/error.rs
🧰 Additional context used
📓 Path-based instructions (2)
**/*.rs
📄 CodeRabbit inference engine (CLAUDE.md)
**/*.rs: Code must be clippy-clean (cargo clippy --all-targets --all-features -- -D warnings)
Code must be formatted with rustfmt (cargo fmt) and pass formatting checks (cargo fmt -- --check)
Write unit tests inline within modules using #[cfg(test)]
Files:
src/error.rs
src/**/*.rs
📄 CodeRabbit inference engine (CLAUDE.md)
src/**/*.rs: Each MP4 atom type must implement the Atom trait with KIND, decode_body(), and encode_body()
Use Header::read_from() to handle large atoms without loading entire contents into memory
All operations should return Result using custom error types defined in error.rs
Use the custom Buf/BufMut traits for contiguous byte slices instead of ad-hoc buffer handling
Files:
src/error.rs
🧠 Learnings (5)
📓 Common learnings
Learnt from: CR
Repo: kixelated/mp4-atom PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-08-31T04:06:57.364Z
Learning: Applies to src/**/*.rs : Each MP4 atom type must implement the Atom trait with KIND, decode_body(), and encode_body()
📚 Learning: 2025-08-31T04:06:57.364Z
Learnt from: CR
Repo: kixelated/mp4-atom PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-08-31T04:06:57.364Z
Learning: Applies to src/**/*.rs : Each MP4 atom type must implement the Atom trait with KIND, decode_body(), and encode_body()
Applied to files:
justfileREADME.mdsrc/error.rs
📚 Learning: 2025-08-31T04:06:57.364Z
Learnt from: CR
Repo: kixelated/mp4-atom PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-08-31T04:06:57.364Z
Learning: Applies to src/**/*.rs : Use Header::read_from() to handle large atoms without loading entire contents into memory
Applied to files:
README.md
📚 Learning: 2025-08-31T04:06:57.364Z
Learnt from: CR
Repo: kixelated/mp4-atom PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-08-31T04:06:57.364Z
Learning: Applies to src/tokio/**/*.rs : For async IO (with the tokio feature), implement and use AsyncReadFrom and AsyncWriteTo traits
Applied to files:
README.md
📚 Learning: 2025-08-31T04:06:57.364Z
Learnt from: CR
Repo: kixelated/mp4-atom PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-08-31T04:06:57.364Z
Learning: Applies to src/any.rs : Register new atom types in the Any enum (src/any.rs) to enable flexible decoding
Applied to files:
src/error.rs
🔇 Additional comments (1)
Cargo.toml (1)
25-30: Feature flag addition looks correct.
strict = []is a clean opt-in switch forcfg!(feature = "strict").
kixelated
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wouldn't do the env variable, but your call.
Replaces the remaining part of #92.