Skip to content

fix(event): support both positional and object args in parse()#172

Open
mateussiqueira wants to merge 1 commit into
starkbank:masterfrom
mateussiqueira:master
Open

fix(event): support both positional and object args in parse()#172
mateussiqueira wants to merge 1 commit into
starkbank:masterfrom
mateussiqueira:master

Conversation

@mateussiqueira

Copy link
Copy Markdown

Bug

event.parse() only accepted a single object parameter via destructuring:

parse({content, signature, user})

But the JSDoc documents positional parameters:

parse(content, signature, user)

When users follow the docs and call parse(content, signature), destructuring the content string yields undefined for all values, causing JSON.parse(undefined)SyntaxError: Unexpected token u in JSON at position 0.

Fix

  1. Check if first arg is a plain object → destructure; otherwise treat as positional
  2. Add input validation: throw clear error if content/signature are missing

Closes #163

The parse() function only accepted a single object parameter via
destructuring:

  parse({content, signature, user})

But its JSDoc documents positional parameters:

  parse(content, signature, user)

When users follow the docs and call parse(content, signature),
destructuring the content string yields undefined for all values,
causing JSON.parse(undefined) → 'Unexpected token u in JSON at position 0'.

Add a compatibility check at the top of the function: if the first
argument is a plain object, use destructuring; otherwise treat them
as positional. Also add input validation so undefined/null content
or signature throws a clear error instead of a cryptic JSON syntax error.

Fixes starkbank#163
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.

[Bug] SyntaxError: Unexpected token u in JSON at position 0 in event.parse (v2.38.0)

1 participant