Skip to content

fix(metassr-build): replace panicking Manifest::from() with proper error handling#101

Open
abhicodes0324 wants to merge 1 commit intometacall:masterfrom
abhicodes0324:fix/manifest-panic-error-handling
Open

fix(metassr-build): replace panicking Manifest::from() with proper error handling#101
abhicodes0324 wants to merge 1 commit intometacall:masterfrom
abhicodes0324:fix/manifest-panic-error-handling

Conversation

@abhicodes0324
Copy link

Problem

Manifest::from() called .unwrap() twice with no error context:

let content = read_to_string(path).unwrap();  // panics if file missing
serde_json::from_str(&content).unwrap()        // panics if JSON malformed

This causes two real user-facing problems:

  1. Running metassr run without building first - manifest.json doesn't exist yet, so the server panics immediately with a cryptic thread panic instead of a clear message.

  2. Corrupted or partial build - if manifest.json exists but is malformed, the server panics with no indication of what went wrong.

Additionally, page.rs called manifest.get(route).unwrap() which panics if a route exists in the server but not in the manifest.

Changes

manifest.rs

  • Removed panicking From<&S> impl
  • Added Manifest::load() returning Result<Self> with actionable errors:
    • Missing file → "Could not read manifest.json at ...: Did you run metassr build first?"
    • Malformed JSON → "manifest.json is malformed: ..."

renderer/page.rs

  • Manifest::from(path)Manifest::load(path)?
  • manifest.get(route).unwrap().ok_or_else(|| anyhow!(...))?

Before / After

# Before — cryptic panic with no context thread 'main' panicked at 'called `Option::unwrap()` on a `None` value'

# After — actionable error message
Error: Could not read manifest.json at "dist/manifest.json": No such file or directory. Did you run `metassr build` first?

Note

Could not verify output locally due to the MetaCall native dependency requirement. The correctness of this fix can be verified by code review - Manifest::load() uses map_err with ? propagation instead of .unwrap(), making panics structurally impossible for both the missing file and malformed JSON cases.

…ror handling

Signed-off-by: Abhiswant Chaudhary <abhicodes0324@gmail.com>
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.

1 participant