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

Skip to content

Commit db612b3

Browse files
committed
chore: reprot json error as param diagnostic
1 parent 7a1622d commit db612b3

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

coderd/dynamicparameters/static.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func (r *Loader) staticRender(ctx context.Context, db database.Store) (*staticRe
4848
},
4949
// Always use the default, since we used to assume the empty string
5050
Value: previewtypes.StringLiteral(it.DefaultValue),
51-
Diagnostics: nil,
51+
Diagnostics: make(previewtypes.Diagnostics, 0),
5252
}
5353

5454
if it.ValidationError != "" || it.ValidationRegex != "" || it.ValidationMonotonic != "" {
@@ -82,7 +82,15 @@ func (r *Loader) staticRender(ctx context.Context, db database.Store) (*staticRe
8282
}
8383

8484
var protoOptions []*sdkproto.RichParameterOption
85-
_ = json.Unmarshal(it.Options, &protoOptions) // Not going to make this fatal
85+
err := json.Unmarshal(it.Options, &protoOptions)
86+
if err != nil {
87+
param.Diagnostics = append(param.Diagnostics, &hcl.Diagnostic{
88+
Severity: hcl.DiagError,
89+
Summary: "Failed to parse json parameter options",
90+
Detail: err.Error(),
91+
})
92+
}
93+
8694
for _, opt := range protoOptions {
8795
param.Options = append(param.Options, &previewtypes.ParameterOption{
8896
Name: opt.Name,
@@ -97,7 +105,7 @@ func (r *Loader) staticRender(ctx context.Context, db database.Store) (*staticRe
97105
// for a given set of conditions.
98106
_, param.FormType, _ = provider.ValidateFormType(provider.OptionType(param.Type), len(param.Options), param.FormType)
99107

100-
param.Diagnostics = previewtypes.Diagnostics(param.Valid(param.Value))
108+
param.Diagnostics = append(param.Diagnostics, previewtypes.Diagnostics(param.Valid(param.Value))...)
101109
params = append(params, param)
102110
}
103111

0 commit comments

Comments
 (0)