Skip to content

Make MediaType own its canonical display-string parser #746

Description

@forkwright

Finding

aggelmata::MediaType owns the canonical eight-variant media domain and its Display strings, but it does not own the inverse parse. Kritike health checking and Apotheke play history therefore each carry an exact private parser for the same eight strings.

This is distinct from the already-canonical wants.media_type mapping (music_album / tv_series etc.). The duplicated functions reverse the ordinary Display representation exactly, including news.

Verified against main 65644113e47814c87eaba14a6f322820974b8780.

Evidence

  • crates/aggelmata/src/media.rs:8-32 defines the eight MediaType variants and their canonical display strings: music, audiobook, book, comic, podcast, news, movie, tv.
  • aggelmata/src/media.rs:35-71 already demonstrates the intended ownership pattern for the separate wants-schema vocabulary through as_want_str and parse_want_str, explicitly calling itself the single source of truth.
  • crates/kritike/src/health.rs:181-193 defines parse_media_type by matching those eight Display strings to the eight variants.
  • crates/apotheke/src/repo/play_history/mod.rs:162-174 defines the same parse_media_type byte-for-byte.
  • Both callers deliberately return None for unknown/future values rather than defaulting to Music; that error policy can be preserved by a canonical FromStr/parse implementation.

No open issue owns this inverse mapping.

Why this matters

A new media type or rename currently requires changing the enum/Display implementation and then discovering every private inverse matcher. Missing one makes persisted/query data readable in some subsystems and silently skipped in others.

The type already exists specifically to prevent primitive string drift across subsystem boundaries. Leaving its ordinary string parser outside the type defeats that ownership on the read path.

Desired correction

Add one canonical parser for the ordinary MediaType string representation in aggelmata—for example FromStr or MediaType::parse—with an explicit unknown-value error/Option contract. Make Kritike and Apotheke delegate to it and retain parse_want_str for the intentionally different wants-table vocabulary.

Done when:

  • every string emitted by MediaType::Display round-trips through one parser;
  • unknown/future strings fail explicitly rather than defaulting;
  • Kritike and Apotheke contain no local eight-way media-type match;
  • wants-schema parsing remains a separate named mapping; and
  • a test fails if a new MediaType variant gains a Display value without inverse parsing support.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    refactorCode quality and architecture improvementstech-debtTechnical debt and cleanup

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions