chore: improve dynamic parameter validation errors (#18501)

`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.
This commit is contained in:
Steven Masley
2025-06-23 15:08:18 -05:00
committed by GitHub
parent f6e4ba6ed9
commit 5ed0c7abcb
6 changed files with 168 additions and 56 deletions
+3 -11
View File
@@ -752,20 +752,12 @@ func (b *Builder) getDynamicParameters() (names, values []string, err error) {
return nil, nil, BuildError{http.StatusInternalServerError, "failed to check if first build", err}
}
buildValues, diagnostics := dynamicparameters.ResolveParameters(b.ctx, b.workspace.OwnerID, render, firstBuild,
buildValues, err := dynamicparameters.ResolveParameters(b.ctx, b.workspace.OwnerID, render, firstBuild,
lastBuildParameters,
b.richParameterValues,
presetParameterValues)
if diagnostics.HasErrors() {
// TODO: Improve the error response. The response should include the validations for each failed
// parameter. The response should also indicate it's a validation error or a more general form failure.
// For now, any error is sufficient.
return nil, nil, BuildError{
Status: http.StatusBadRequest,
Message: fmt.Sprintf("%d errors occurred while resolving parameters", len(diagnostics)),
Wrapped: diagnostics,
}
if err != nil {
return nil, nil, xerrors.Errorf("resolve parameters: %w", err)
}
names = make([]string, 0, len(buildValues))