Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Security Solution] OpenAPI stringifyZodError generates verbose and confusing error message #182935

Open
machadoum opened this issue May 8, 2024 · 4 comments
Labels
bug Fixes for quality problems that affect the customer experience Team:Detection Rule Management Security Detection Rule Management Team Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. triage_needed

Comments

@machadoum
Copy link
Member

Describe the bug:
The function stringifyZodError which is used by buildRouteValidationWithZod returns verbose and confusing error messages for some OpenAPI schemas.

Current behavior:
Given the schema defined here:

the following test:

it('rejects if neither host nor user weight are specified', () => {

Produces the error meesgae:
'host: Required, user: Required, type: Invalid literal value, expected "risk_category", value: Invalid literal value, expected "category_1", host: Required, and 3 more'

Expected behavior:
The previous implementation (without OpenAPI) used to produce a more readable error message:

[
    'Invalid value "undefined" supplied to "host"',
    'Invalid value "undefined" supplied to "user"',
]
@machadoum machadoum added bug Fixes for quality problems that affect the customer experience triage_needed Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. labels May 8, 2024
@elasticmachine
Copy link
Contributor

Pinging @elastic/security-solution (Team: SecuritySolution)

@machadoum machadoum added the Team:Detection Rule Management Security Detection Rule Management Team label May 8, 2024
@elasticmachine
Copy link
Contributor

Pinging @elastic/security-detection-rule-management (Team:Detection Rule Management)

@marshallmain
Copy link
Contributor

Can you add the old zod schema implementation here for comparison?

@marshallmain
Copy link
Contributor

Also, using a discriminated union on type for RiskScoreWeight will likely make the error message a lot clearer. We have an example of how to add a discriminant here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Fixes for quality problems that affect the customer experience Team:Detection Rule Management Security Detection Rule Management Team Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. triage_needed
Projects
None yet
Development

No branches or pull requests

3 participants