Skip to content

Replace panicking From impls with TryFrom for untrusted export/API data #52

Description

@lmorchard

Found during a code-review pass (2026-07-23). Related to #14 and #35.

Several infallible From conversions .unwrap() on untrusted export/API JSON, so one malformed record panics the whole import/fetch instead of being skipped or reported.

  • impl From<serde_json::Value> for Actorserde_json::from_value(value).unwrap() (src/activitystreams.rs), invoked on export data in src/mastodon/importer.rs. Actor has many non-optional fields; any missing/renamed field or bad published timestamp aborts import.
  • impl From<Status> for Activityurl::Url::parse(status.uri).unwrap() (src/activitystreams.rs), on remote API responses in src/mastodon/fetcher.rs.
  • Related panics in the fetch hot path: access_token...unwrap() (panics when running fetch before mastodon link — see Bug: Crash when attempting mastodon fetch against new instance, because actors haven't been populated #35), actors.get(actor_id).unwrap(), activity.actor.id().unwrap() in src/mastodon/fetcher.rs, and unwrap()s over unresolved actors in src/site_generator.rs.

Suggested fix

Replace the infallible From impls with TryFrom (or call serde_json::from_value/Url::parse at the call site with ?) so callers can skip-with-warning or report bad records. Turn the token/actor lookups into checked errors with actionable messages.

Severity: high (crash-on-malformed-input across the two main ingest paths).

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

    bugSomething isn't workingcode-qualityMaintainability, refactoring, tech debt

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions