Skip to content

Commit 31fdd9c

Browse files
authored
Refactor export validation error handling. (#681)
Improve error reporting by replacing direct error returns with detailed validation result handling. This ensures better clarity and consistency in identifying and addressing validation errors in both `addexport` and `editexport` commands. Signed-off-by: Alberto Ricart <alberto@synadia.com>
1 parent 8305343 commit 31fdd9c

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

cmd/addexport.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,9 @@ func (p *AddExportParams) Validate(ctx ActionCtx) error {
283283
}
284284
// get the old validation results
285285
var vr jwt.ValidationResults
286-
if err = p.claim.Exports.Validate(&vr); err != nil {
287-
return err
286+
p.claim.Exports.Validate(&vr)
287+
if len(vr.Errors()) != 0 {
288+
return vr.Errors()[0]
288289
}
289290

290291
// if we have a latency report subject create it
@@ -296,8 +297,9 @@ func (p *AddExportParams) Validate(ctx ActionCtx) error {
296297
p.claim.Exports.Add(&p.export)
297298

298299
var vr2 jwt.ValidationResults
299-
if err = p.claim.Exports.Validate(&vr2); err != nil {
300-
return err
300+
p.claim.Exports.Validate(&vr2)
301+
if len(vr2.Errors()) != 0 {
302+
return vr2.Errors()[0]
301303
}
302304

303305
// filter out all the old validations

cmd/editexport.go

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -349,11 +349,17 @@ func (p *EditExportParams) Run(ctx ActionCtx) (store.Status, error) {
349349
old := *p.claim.Exports[p.index]
350350
// old vr
351351
var vr jwt.ValidationResults
352-
if err := p.claim.Exports.Validate(&vr); err != nil {
353-
return nil, err
352+
r := store.NewDetailedReport(false)
353+
354+
p.claim.Exports.Validate(&vr)
355+
if len(vr.Errors()) != 0 {
356+
errs := vr.Errors()
357+
for _, err := range errs {
358+
r.AddFromError(err)
359+
}
360+
return r, vr.Errors()[0]
354361
}
355362

356-
r := store.NewDetailedReport(false)
357363
var export jwt.Export
358364
export.Name = p.name
359365
if export.Name != old.Name {
@@ -437,9 +443,15 @@ func (p *EditExportParams) Run(ctx ActionCtx) (store.Status, error) {
437443
p.claim.Exports[p.index] = &export
438444

439445
var vr2 jwt.ValidationResults
440-
if err := p.claim.Exports.Validate(&vr2); err != nil {
441-
return nil, err
446+
p.claim.Exports.Validate(&vr2)
447+
if len(vr2.Errors()) != 0 {
448+
errs := vr2.Errors()
449+
for _, err := range errs {
450+
r.AddFromError(err)
451+
}
452+
return r, vr2.Errors()[0]
442453
}
454+
443455
// filter out all the old validations
444456
uvr := jwt.CreateValidationResults()
445457
if len(vr.Issues) > 0 {

0 commit comments

Comments
 (0)