Skip to content

Commit

Permalink
Better error message
Browse files Browse the repository at this point in the history
  • Loading branch information
hknutzen committed Apr 3, 2024
1 parent 0490096 commit 7282ab5
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 4 deletions.
2 changes: 1 addition & 1 deletion go/pkg/api/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ func (s *state) getToplevel(name string, c change) (ast.Toplevel, error) {
m, ok := c.val.(map[string]interface{})
if !ok {
return nil, fmt.Errorf(
"Expecting JSON object when reading '%s' but got: %T", name, c.val)
"Expecting JSON object in attribute 'value' but got: %T", c.val)
}
var t ast.Toplevel
var err error
Expand Down
2 changes: 1 addition & 1 deletion go/testdata/api/group.t
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ network:n1 = { ip = 10.1.1.0/24; }
}
}
=ERROR=
Error: Expecting JSON object when reading 'group:g1' but got: []interface {}
Error: Expecting JSON object in attribute 'value' but got: []interface {}
=END=
############################################################
Expand Down
35 changes: 34 additions & 1 deletion go/testdata/api/path.t
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,39 @@ network:n1 = { ip = 10.1.1.0/24; }
Error: Invalid empty path
=END=
############################################################
=TITLE=Invalid path
=INPUT=
network:n1 = { ip = 10.1.1.0/24; }
=JOB=
{
"method": "add",
"params": { "path": "invalid" }
}
=ERROR=
Error: Expecting JSON object in attribute 'value' but got: <nil>
=END=
############################################################
=TITLE=Invalid global definition
=INPUT=
network:n1 = { ip = 10.1.1.0/24; }
=JOB=
{
"method": "add",
"params": { "path": "in:valid", "value": {} }
}
=ERROR=
Error: Unknown global definition at line 3 of INPUT, near "--HERE-->in:valid"
Aborted
=OUTPUT=
@@ INPUT
network:n1 = { ip = 10.1.1.0/24; }
+
+in:valid = {
+}
=END=
############################################################
=TITLE=Invalid value
=INPUT=
Expand All @@ -38,7 +71,7 @@ network:n1 = { ip = 10.1.1.0/24; }
}
}
=ERROR=
Error: Expecting JSON object when reading 'network:n2' but got: []interface {}
Error: Expecting JSON object in attribute 'value' but got: []interface {}
=END=
############################################################
Expand Down
2 changes: 1 addition & 1 deletion go/testdata/api/service.t
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ network:n1 = { ip = 10.1.1.0/24; }
}
}
=ERROR=
Error: Expecting JSON object when reading 'service:s1' but got: string
Error: Expecting JSON object in attribute 'value' but got: string
=END=
############################################################
Expand Down

0 comments on commit 7282ab5

Please sign in to comment.