Skip to content

fix(options): return explicit error on invalid JSON options - #417

Open
luojiyin1987 wants to merge 3 commits into
thx:mainfrom
luojiyin1987:fix/options-error-handling
Open

luojiyin1987 wants to merge 3 commits into
thx:mainfrom
luojiyin1987:fix/options-error-handling

Conversation

@luojiyin1987

Copy link
Copy Markdown

Changes

Fix silent fallback when invalid JSON options are passed to Resvg constructor.

Before

// Typo in option name - no error, uses defaults
const resvg = new Resvg(svg, { dpii: 96 })

After

// Throws: Invalid options: unknown field `dpii`, expected one of `font`, `dpi`, ...
const resvg = new Resvg(svg, { dpii: 96 })

Implementation

  1. Added InvalidOptions error variant in src/error.rs
  2. Changed src/lib.rs N-API and Wasm constructors to return explicit errors instead of .ok() fallback

Error Types Handled

  • JSON syntax errors
  • Unknown fields (via deny_unknown_fields)
  • Invalid field values (e.g., negative numbers for u32)
  • Type mismatches

Closes #416

@vercel

vercel Bot commented Aug 15, 2026

Copy link
Copy Markdown

@luojiyin1987 is attempting to deploy a commit to the yisibl's projects Team on Vercel.

A member of the Team first needs to authorize it.

This branch has not been deployed

No deployments
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.

fix(options): return explicit error on invalid JSON options

1 participant