Commit f65c19a
fix: improve validation error messages with specific type information
Make validateRequiredField and validateOptionalField errors more specific
and helpful for debugging by including expected and received types.
Problem:
- Generic error messages like "invalid field XXX" don't tell developers
what went wrong or how to fix it
- Debugging type mismatches requires manual inspection
- User experience suffers from vague error messages
Solution:
Added inferTypeName() helper function that maps validator functions
to human-readable type descriptions:
Type Mappings:
- isString → "a string"
- isNumber → "a number"
- isAccount → "a valid account address"
- isAmount → "a valid amount"
- isRecord → "an object"
- isArray → "an array"
- isMemo → "a valid Memo"
- isCurrency → "a valid Currency"
- isXRPLNumber → "a valid XRPL number string"
- And 10+ more type validators
Error Message Improvements:
Before:
"Payment: invalid field Amount"
After:
"Payment: Amount must be a valid amount, received string"
Before:
"TrustSet: invalid field Account"
After:
"TrustSet: Account must be a valid account address, received undefined"
Benefits:
✅ Clear expected vs actual type information
✅ Immediate understanding of what's wrong
✅ Better developer experience
✅ Faster debugging
✅ Reduced support burden
✅ Self-documenting error messages
Implementation:
- inferTypeName() extracts type from validator function name
- Falls back to generic "valid" for custom validators
- No breaking changes to existing API
- Works with all existing validation calls
- Zero performance impact (name lookup once per error)
Coverage:
- validateRequiredField: Enhanced with type-specific messages
- validateOptionalField: Enhanced with type-specific messages
- All transaction validators automatically benefit
Examples of improved errors:
- "Fee must be a string, received number"
- "Sequence must be a number, received string"
- "Memos must be an array, received object"
- "Account must be a valid account address, received undefined"
Testing:
- All existing tests pass
- Error messages now include type information
- Backward compatible (no API changes)
Fixes #2858
Co-authored-by: Cursor <cursoragent@cursor.com>1 parent be8d9a2 commit f65c19a
1 file changed
+39
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
372 | 372 | | |
373 | 373 | | |
374 | 374 | | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
375 | 408 | | |
376 | 409 | | |
377 | 410 | | |
| |||
406 | 439 | | |
407 | 440 | | |
408 | 441 | | |
| 442 | + | |
| 443 | + | |
409 | 444 | | |
410 | | - | |
| 445 | + | |
411 | 446 | | |
412 | 447 | | |
413 | 448 | | |
| |||
440 | 475 | | |
441 | 476 | | |
442 | 477 | | |
| 478 | + | |
| 479 | + | |
443 | 480 | | |
444 | | - | |
| 481 | + | |
445 | 482 | | |
446 | 483 | | |
447 | 484 | | |
| |||
0 commit comments