Skip to content

Handle unsupported ID3 frames in MP3 Quick Cleanse (remove TENC, add safeSetFrame)#31

Merged
ChrisAdamsdevelopment merged 1 commit into
mainfrom
codex/fix-unsupported-id3-frame-tenc-in-quick-cleanse
May 18, 2026
Merged

Handle unsupported ID3 frames in MP3 Quick Cleanse (remove TENC, add safeSetFrame)#31
ChrisAdamsdevelopment merged 1 commit into
mainfrom
codex/fix-unsupported-id3-frame-tenc-in-quick-cleanse

Conversation

@ChrisAdamsdevelopment
Copy link
Copy Markdown
Owner

@ChrisAdamsdevelopment ChrisAdamsdevelopment commented May 18, 2026

Motivation

  • Quick Cleanse was failing when writeMP3Metadata attempted to write an unsupported TENC ID3 frame and thus aborted the whole metadata rewrite.
  • The change makes metadata writing resilient so optional unsupported frames are skipped with a warning instead of breaking the cleanse.

Description

  • Updated writeMP3Metadata in src/utils/metadata.js to add a local safeSetFrame(frameId, value) helper that wraps writer.setFrame in try/catch and logs a warning when a frame is unsupported.
  • Removed writing of the TENC frame entirely so the known unsupported frame is no longer written.
  • Switched writes for the supported fields to use safeSetFrame: TIT2 (title), TPE1 (artist), and TCON (genre).
  • Preserved existing error handling for true failures (addTag, getBlob, unreadable input) so the function still returns a Blob on success or throws a useful error on real failures, and no other files were changed.

Testing

  • Ran npm run build; the build failed due to pre-existing TypeScript/dependency/React typing issues unrelated to this metadata change, so no full app build could be validated here.
  • Unit/manual runtime behavior expected: Quick Cleanse should no longer fail on TENC, and when TIT2, TPE1, or TCON are present they are written if supported while unsupported frames are skipped with a console warning (no failure).

Codex Task

Summary by Sourcery

Improve resilience of MP3 metadata writing in Quick Cleanse by safely handling unsupported ID3 frames and stopping use of a known unsupported frame.

Bug Fixes:

  • Prevent Quick Cleanse from failing when attempting to write unsupported ID3 frames by skipping them instead of aborting metadata rewriting.

Enhancements:

  • Introduce a safe frame-writing helper for ID3 metadata that logs warnings and continues when frames are unsupported.
  • Stop writing the unsupported TENC ID3 frame while preserving existing error handling for genuine write failures.

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented May 18, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Makes MP3 Quick Cleanse metadata writing resilient to unsupported ID3 frames by introducing a safe frame setter, routing supported frames through it, and removing the known-unsupported TENC frame write while preserving existing error handling behavior.

Sequence diagram for safeSetFrame usage in writeMP3Metadata

sequenceDiagram
  participant QC as QuickCleanse
  participant writeMP3Metadata
  participant safeSetFrame
  participant writer
  participant console

  QC->>writeMP3Metadata: writeMP3Metadata(file, metadata)
  writeMP3Metadata->>safeSetFrame: safeSetFrame(TIT2, title)
  safeSetFrame->>writer: setFrame(TIT2, title)
  alt frame_supported
    writer-->>safeSetFrame: success
    safeSetFrame-->>writeMP3Metadata: true
  else frame_unsupported
    writer-->>safeSetFrame: throw error
    safeSetFrame->>console: warn([quick-cleanse] skipped unsupported ID3 frame)
    safeSetFrame-->>writeMP3Metadata: false
  end
  writeMP3Metadata->>safeSetFrame: safeSetFrame(TPE1, [artist])
  writeMP3Metadata->>safeSetFrame: safeSetFrame(TCON, [genre])
  writeMP3Metadata->>writer: addTag()
  writer-->>writeMP3Metadata: Blob
  writeMP3Metadata-->>QC: Blob
Loading

File-Level Changes

Change Details Files
Harden MP3 ID3 metadata writing by wrapping frame writes in a safe helper and removing the unsupported TENC frame.
  • Introduce a local safeSetFrame(frameId, value) helper that wraps writer.setFrame in try/catch and logs a console warning when a frame is unsupported, returning a boolean success flag.
  • Route existing writes for title (TIT2), artist (TPE1), and genre (TCON) through safeSetFrame instead of calling writer.setFrame directly.
  • Remove the write of the TENC encoder frame so the known unsupported frame is never attempted.
  • Leave the surrounding try/catch that wraps addTag and other writer operations intact so failures still surface as a single descriptive error while frame-level unsupported errors are downgraded to warnings.
src/utils/metadata.js

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@ChrisAdamsdevelopment ChrisAdamsdevelopment merged commit 0bdcade into main May 18, 2026
4 of 5 checks passed
Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • The safeSetFrame helper currently swallows all errors from writer.setFrame; consider narrowing the catch to only the known unsupported-frame error shape (or at least checking an error code/message) so genuine write failures don’t get silently downgraded to warnings.
  • If safeSetFrame is intended to be reused elsewhere, it may be worth extracting it to a shared utility (or at least outside writeMP3Metadata) and adding some context (e.g., file name) to the warning to make troubleshooting skipped frames easier.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The `safeSetFrame` helper currently swallows all errors from `writer.setFrame`; consider narrowing the catch to only the known unsupported-frame error shape (or at least checking an error code/message) so genuine write failures don’t get silently downgraded to warnings.
- If `safeSetFrame` is intended to be reused elsewhere, it may be worth extracting it to a shared utility (or at least outside `writeMP3Metadata`) and adding some context (e.g., file name) to the warning to make troubleshooting skipped frames easier.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant