Thanks to visit codestin.com
Credit goes to github.com

Skip to content

chore: improve dynamic parameter validation errors #18501

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

Merged
merged 2 commits into from
Jun 23, 2025

Conversation

Emyrk
Copy link
Member

@Emyrk Emyrk commented Jun 23, 2025

What this does

The current BuildError response from wsbuilder does not support rich errors from validation. Changed this to use the Validations block of codersdk responses to return all errors for invalid parameters.


Example http response

{
    "message": "Unable to validate parameters",
    "validations": [
        {
            "field": "big_number",
            "detail": "Invalid parameter value according to 'validation' block; Number must be between 500 and 1000"
        },
        {
            "field": "colors",
            "detail": "Values must be a valid option; Value \"[\\\"potatoe\\\"]\" is not a valid option, values \"potatoe\" are missing from the options"
        },
        {
            "field": "intro",
            "detail": "Invalid parameter value according to 'validation' block; All messages must start with 'Hello' (value \"Goodbye!\" does not match \"^Hello\")"
        }
    ]
}

Cli error

Screenshot From 2025-06-23 10-17-26

Copy link
Member Author

Emyrk commented Jun 23, 2025

@Emyrk Emyrk force-pushed the stevenmasley/dynamic_validate branch from 0e3dc00 to a51570a Compare June 23, 2025 14:31
@Emyrk Emyrk force-pushed the stevenmasley/dynamic_valid_errors branch 3 times, most recently from 0923f4d to 817afe8 Compare June 23, 2025 15:20
@Emyrk Emyrk marked this pull request as ready for review June 23, 2025 15:21
@Emyrk Emyrk changed the base branch from stevenmasley/dynamic_validate to graphite-base/18501 June 23, 2025 16:11
@Emyrk Emyrk force-pushed the graphite-base/18501 branch from 4f52076 to c1d05a0 Compare June 23, 2025 16:45
@Emyrk Emyrk force-pushed the stevenmasley/dynamic_valid_errors branch from 817afe8 to 21556db Compare June 23, 2025 16:45
@Emyrk Emyrk changed the base branch from graphite-base/18501 to stevenmasley/dynamic_validate June 23, 2025 16:45
@Emyrk Emyrk force-pushed the stevenmasley/dynamic_validate branch from c1d05a0 to 129235b Compare June 23, 2025 16:59
@Emyrk Emyrk force-pushed the stevenmasley/dynamic_valid_errors branch from 21556db to 5f30d20 Compare June 23, 2025 17:00
@Emyrk Emyrk force-pushed the stevenmasley/dynamic_validate branch from 129235b to 6a5ee9e Compare June 23, 2025 17:04
@Emyrk Emyrk force-pushed the stevenmasley/dynamic_valid_errors branch from 5f30d20 to 40063cd Compare June 23, 2025 17:04
@Emyrk Emyrk force-pushed the stevenmasley/dynamic_validate branch 2 times, most recently from 0523a2f to f4e5548 Compare June 23, 2025 17:18
@Emyrk Emyrk force-pushed the stevenmasley/dynamic_valid_errors branch 2 times, most recently from 686b2f7 to 6849a80 Compare June 23, 2025 17:18
@Emyrk Emyrk force-pushed the stevenmasley/dynamic_validate branch from f4e5548 to 0523a2f Compare June 23, 2025 17:18
@Emyrk Emyrk changed the base branch from stevenmasley/dynamic_validate to graphite-base/18501 June 23, 2025 17:35
@Emyrk Emyrk force-pushed the graphite-base/18501 branch from 0523a2f to 82af2e0 Compare June 23, 2025 17:35
@Emyrk Emyrk force-pushed the stevenmasley/dynamic_valid_errors branch from 6849a80 to a5f35dd Compare June 23, 2025 17:35
@graphite-app graphite-app bot changed the base branch from graphite-base/18501 to main June 23, 2025 17:36
@Emyrk Emyrk force-pushed the stevenmasley/dynamic_valid_errors branch from a5f35dd to 3c2904c Compare June 23, 2025 17:36
@Emyrk Emyrk requested a review from johnstcn June 23, 2025 17:36
Comment on lines +30 to +31
Diagnostics hcl.Diagnostics
Parameter map[string]hcl.Diagnostics
Copy link
Member

Choose a reason for hiding this comment

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

suggestion: unexport and return a clone via method?

Copy link
Member Author

Choose a reason for hiding this comment

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

No one should really mutate the diagnostics. But I can do that 👍

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually I am going to leave it for now. If I make a method to export it, I would either need 1 method to return both diag sets. Or 2 methods. I think the usage is less intuitive in those cases.

func (e *ResolveError) Diagnostics()(hcl.Diagnostics, map[string]hcl.Diagnostics)

// Or

// This name is not ideal, since Diagnostics does not include the parameter ones :thinking: 
func (e *ResolveError) Diagnostics()(hcl.Diagnostics)
func (e *ResolveError) ParameterDiagnostics()(map[string]hcl.Diagnostics)

Validations: nil,
}

for name, diag := range parameterErr.Parameter {
Copy link
Member

Choose a reason for hiding this comment

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

suggestion: sort map keys for deterministic output?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good idea 👍

@Emyrk Emyrk merged commit 5ed0c7a into main Jun 23, 2025
35 checks passed
@Emyrk Emyrk deleted the stevenmasley/dynamic_valid_errors branch June 23, 2025 20:08
@github-actions github-actions bot locked and limited conversation to collaborators Jun 23, 2025
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