Skip to content

Commit

Permalink
chore: change parsing UnmarshalJSON error prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
d-strobel committed Dec 29, 2024
1 parent 2ec5ff1 commit 1a0215e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion parsing/cim_class_key_val.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (kv *CimClassKeyVal) UnmarshalJSON(b []byte) error {
// Regular expression to match key-value pairs with quoted and unquoted values.
pairRegex, err := regexp.Compile(`(\S+)\s*=\s*("(.*?)"|'(.*?)'|(\S+))`)
if err != nil {
return fmt.Errorf("parsing.CimClassKeyVal.UnmarshalJSON: %s", err)
return fmt.Errorf("parsing.UnmarshalJSON(CimClassKeyVal): %s", err)
}

// Find all key-value pairs in the input string.
Expand Down
8 changes: 4 additions & 4 deletions parsing/dotnet_time.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,24 @@ func (t *DotnetTime) UnmarshalJSON(b []byte) error {
// Check for valid dotnet timestring
re, err := regexp.Compile(`^"\\/Date\(\d+\)\\/"$`)
if err != nil {
return fmt.Errorf("parsing.DotnetTime.UnmarshalJSON: %s", err)
return fmt.Errorf("parsing.UnmarshalJSON(DotnetTime): %s", err)
}

if !re.Match(b) {
return fmt.Errorf("parsing.DotnetTime.UnmarshalJSON: input string is not a dotnet JSON datetime: %s", string(b))
return fmt.Errorf("parsing.UnmarshalJSON(DotnetTime): input string is not a dotnet JSON datetime: %s", string(b))
}

// Extract timestamp
re, err = regexp.Compile(`\d+`)
if err != nil {
return fmt.Errorf("parsing.DotnetTime.UnmarshalJSON: %s", err)
return fmt.Errorf("parsing.UnmarshalJSON(DotnetTime): %s", err)
}
timestamp := re.Find(b)

// Convert to seconds
i, err := strconv.Atoi(string(timestamp))
if err != nil {
return fmt.Errorf("parsing.DotnetTime.UnmarshalJSON: %s", err)
return fmt.Errorf("parsing.UnmarshalJSON(DotnetTime): %s", err)
}
seconds := int64(i / 1000)

Expand Down
2 changes: 1 addition & 1 deletion parsing/dotnet_time_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (suite *DotnetTimeUnitTestSuite) TestUnmarshalJSON() {
suite.Run("should return error with invalid dotnet timestring", func() {
winTime := DotnetTime{}
err := winTime.UnmarshalJSON([]byte("2023-20-10"))
suite.ErrorContains(err, "parsing.DotnetTime.UnmarshalJSON: input string is not a dotnet JSON datetime")
suite.ErrorContains(err, "parsing.UnmarshalJSON(DotnetTime): input string is not a dotnet JSON datetime")
})

suite.Run("should unmarshal the whole json object correctly", func() {
Expand Down

0 comments on commit 1a0215e

Please sign in to comment.