Skip to content

Enhance error handling and reporting for app data deserialization#4213

Merged
jmg-duarte merged 5 commits intomainfrom
jmgd/app_data/error
Mar 2, 2026
Merged

Enhance error handling and reporting for app data deserialization#4213
jmg-duarte merged 5 commits intomainfrom
jmgd/app_data/error

Conversation

@jmg-duarte
Copy link
Copy Markdown
Contributor

@jmg-duarte jmg-duarte commented Feb 26, 2026

Description

When users provide app data with wrong partner fees, we get less than good error reporting, for example:

{"errorType":"AppDataInvalid","description":"app data has the wrong format: data did not match any variant of untagged enum Helper at line 1 column 232"}

This is, not only a pain for us to debug but also for the user:

  • For us because the special deserializers are all named Helper
  • For the user because of the bad error message

This PR changes the deserialization mechanism in a "non-obvious" way to provide proper error messages, as untagged enums stand very much against them.

For example floating point bps are unsupported, they returned the previous error; after this PR they return:

{"errorType":"AppDataInvalid","description":"app data has the wrong format: invalid type: floating point `99.0`, expected u64 at line 1 column 128"}

Changes

  • Rename the deserializers
  • Refactor the deserializers into weird structs (but better for error reporting)

How to test

Unit tests to ensure nothing broke + playground to test the error

curl 'http://localhost:8000/api/v1/app_data \
  -X 'PUT' \
  -H 'accept: application/json' \
  -H 'content-type: application/json' \
  --data-raw '{"fullAppData":"{\"appCode\":\"YOUR_APP_CODE\",\"metadata\":{\"partnerFee\":[{\"recipient\":\"0x28c716bC23ed77CAEc27f476A366318ad5F12d58\",\"volumeBps\":99.5},{\"priceImprovementBps\":9900,\"recipient\":\"0x28c716bC23ed77CAEc27f476A366318ad5F12d58\",\"volumeBps\":100}]},\"version\":\"1.14.0\"}"}'

@jmg-duarte jmg-duarte marked this pull request as ready for review February 27, 2026 14:52
@jmg-duarte jmg-duarte requested a review from a team as a code owner February 27, 2026 14:52
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This PR improves deserialization error handling by replacing #[serde(untagged)] with more explicit logic, which is a sound approach. The changes are well-implemented and achieve the stated goal of providing better error messages. The suggestion to simplify the implementation for PartnerFees by leveraging the serde_with crate is valid and would reduce code complexity.

Copy link
Copy Markdown
Contributor

@MartinquaXD MartinquaXD left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks okay to me.

@jmg-duarte jmg-duarte enabled auto-merge March 2, 2026 10:38
@jmg-duarte jmg-duarte added this pull request to the merge queue Mar 2, 2026
Merged via the queue into main with commit 8842809 Mar 2, 2026
19 checks passed
@jmg-duarte jmg-duarte deleted the jmgd/app_data/error branch March 2, 2026 11:24
@github-actions github-actions Bot locked and limited conversation to collaborators Mar 2, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants