Skip to content

Conversation

@bradh
Copy link
Collaborator

@bradh bradh commented Jan 10, 2026

Replaces the remaining part of #92.

@coderabbitai
Copy link

coderabbitai bot commented Jan 10, 2026

Walkthrough

The 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)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding a strict mode feature and enabling it during testing, which aligns with the changeset modifications to Cargo.toml, README.md, justfile, and src/error.rs.
Description check ✅ Passed The description is related to the changeset as it references issue #92, which provides context for this pull request implementing strict mode functionality.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a 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: “bytes features” → “bytes feature”.
  • Lines 109-110: since code treats “env var is present” as strict, consider clarifying “set MP4ATOM_STRICT (e.g. to 1)” 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 using var_os() for cleaner env handling.

The strict-mode logic is correct. If you add tests for MP4ATOM_STRICT environment variable mutation, use var_os("MP4ATOM_STRICT").is_some() instead of var(...).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 on test. The environment variable controls strict parsing behavior in decode_unknown() (src/error.rs), turning warnings into hard errors. Since cargo check, cargo clippy, and cargo fmt are static analysis tools that don't execute decode logic, the export doesn't functionally affect the check and fix recipes. However, for clarity and to align with the documented use case ("useful... when testing mp4-atom itself"), consider scoping MP4ATOM_STRICT to only the test recipe:

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

📥 Commits

Reviewing files that changed from the base of the PR and between caa033a and 33704b4.

📒 Files selected for processing (4)
  • Cargo.toml
  • README.md
  • justfile
  • src/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:

  • justfile
  • README.md
  • src/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 for cfg!(feature = "strict").

Copy link
Owner

@kixelated kixelated left a 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants