Skip to content

Conversation

@mag123c
Copy link
Contributor

@mag123c mag123c commented Nov 24, 2025

Improves validation error messages to include event names and field paths, making debugging significantly easier.
Fixed #42

Changes

Before:

Error: Validation failed

After:

Validation failed: "user:created"
  - body.email: Invalid email: Received "not-an-email"
  - body.age: Invalid value: Expected >=13 but received 10

Added formatStandardSchemaIssues helper function in src/standard.ts. Formats Standard Schema issues into readable error messages with

  • Event name (when available)
  • Field paths in dot notation
  • Original validation messages from the schema library

Test Approach

Added a single test that validates the core improvement: event name inclusion in error messages.

The test intentionally avoids checking implementation details (specific field names, exact error messages, formatting) and only verifies

.toThrow('Validation failed: "user:created"');

Question: Is this the right level of test coverage? I kept it minimal to

  • Avoid coupling tests to validation library message formats (which may change)
  • Follow the existing test convention (simple string matching with .toThrow())
  • Focus on the key feature: event names in error messages

Notes

Implementation inspired by Zod's prettifyError you mentioned but adapted for Standard Schema's simpler issue format

@tonyfromundefined
Copy link
Member

@mag123c Can you add changeset? You can easily write a version and detailed description with $ yarn changeset . After creating the file, just commit and push it.

@tonyfromundefined
Copy link
Member

I think you should submit it as a patch version.

@tonyfromundefined tonyfromundefined changed the title feat: improve validation error messages fix: improve validation error messages Nov 28, 2025
@mag123c
Copy link
Contributor Author

mag123c commented Nov 28, 2025

@tonyfromundefined added changeset 😃

@tonyfromundefined tonyfromundefined merged commit eacf012 into daangn:main Nov 29, 2025
1 check passed
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.

Improve validation error messages with detailed feedback

2 participants