Skip to content

Commit

Permalink
Wrapping errors, some improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
xBlaz3kx committed Dec 13, 2024
1 parent 366b12c commit 541e948
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
16 changes: 8 additions & 8 deletions parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (p *Parser) GetPayload() (*PayloadSection, error) {
// Validate the payload if automatic validation is enabled
if p.opts.withAutomaticValidation {
if err := p.payload.Validate(); err != nil {
return nil, err
return nil, errors.Wrap(err, "payload validation failed")
}
}

Expand Down Expand Up @@ -102,17 +102,17 @@ func parseOcmfMessageFromString(data string) (*PayloadSection, *Signature, error
return nil, nil, ErrInvalidFormat
}

payloadSection := &PayloadSection{}
err := json.Unmarshal([]byte(splitData[0]), payloadSection)
payloadSection := PayloadSection{}
err := json.Unmarshal([]byte(splitData[0]), &payloadSection)
if err != nil {
return nil, nil, err
return nil, nil, errors.Wrap(err, "failed to unmarshal payload")
}

signature := &Signature{}
err = json.Unmarshal([]byte(splitData[1]), signature)
signature := Signature{}
err = json.Unmarshal([]byte(splitData[1]), &signature)
if err != nil {
return nil, nil, err
return nil, nil, errors.Wrap(err, "failed to unmarshal signature")
}

return payloadSection, signature, nil
return &payloadSection, &signature, nil
}
2 changes: 1 addition & 1 deletion validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func currentTypeValidator(fl validator.FieldLevel) bool {
return isValidCurrentType(CurrentType(fl.Field().String()))
}

var iso8601WithMillisRegex = regexp.MustCompile(`^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2},\d{3}[+-]\d{4}$`)
var iso8601WithMillisRegex = regexp.MustCompile(`^(?:19|20)\d{2}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])T(?:[01]\d|2[0-3]):[0-5]\d:[0-5]\d(?:Z|-0[1-9]|-1\d|-2[0-3]|-00:?(?:0[1-9]|[1-5]\d)|\+[01]\d|\+2[0-3])(?:|:?[0-5]\d)$`)

func iso8601WithMillisValidator(fl validator.FieldLevel) bool {
return iso8601WithMillisRegex.MatchString(fl.Field().String())
Expand Down

0 comments on commit 541e948

Please sign in to comment.