Skip to content

Commit

Permalink
Adjust runtime error handlers, convert to static properties
Browse files Browse the repository at this point in the history
Signed-off-by: Sean Williams <72675818+sean-r-williams@users.noreply.github.com>
  • Loading branch information
sean-r-williams committed Mar 28, 2024
1 parent 2627f16 commit 0aa8987
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 10 deletions.
10 changes: 5 additions & 5 deletions ast/builtins.go
Original file line number Diff line number Diff line change
Expand Up @@ -1718,11 +1718,11 @@ var JSONMarshalWithOptions = &Builtin{
types.Named("opts", types.NewAny(
types.NewNull(),
types.NewObject(
nil,
types.NewDynamicProperty(
types.S,
types.A,
),
[]*types.StaticProperty{
types.NewStaticProperty("indent", types.NewAny(types.S, types.NewNull())),
types.NewStaticProperty("prefix", types.NewAny(types.S, types.NewNull())),
},
types.NewDynamicProperty(types.S, types.A),
),
)).Description("encoding options - accepts keys `prefix` (string to prefix lines with, default empty string) and `indent` (string to indent with, default `\\t`)"),
),
Expand Down
2 changes: 1 addition & 1 deletion builtin_metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -10389,7 +10389,7 @@
{
"description": "encoding options - accepts keys `prefix` (string to prefix lines with, default empty string) and `indent` (string to indent with, default `\\t`)",
"name": "opts",
"type": "any\u003cnull, object[string: any]\u003e"
"type": "any\u003cnull, object\u003cindent: any\u003cnull, string\u003e, prefix: any\u003cnull, string\u003e\u003e[string: any]\u003e"
}
],
"available": [
Expand Down
30 changes: 30 additions & 0 deletions capabilities.json
Original file line number Diff line number Diff line change
Expand Up @@ -2212,6 +2212,36 @@
"type": "any"
}
},
"static": [
{
"key": "indent",
"value": {
"of": [
{
"type": "null"
},
{
"type": "string"
}
],
"type": "any"
}
},
{
"key": "prefix",
"value": {
"of": [
{
"type": "null"
},
{
"type": "string"
}
],
"type": "any"
}
}
],
"type": "object"
}
],
Expand Down
8 changes: 4 additions & 4 deletions topdown/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ func builtinJSONMarshalWithOpts(_ BuiltinContext, operands []*ast.Term, iter fun

val := marshalOpts.Get(k)

key, err := builtins.StringOperand(k.Value, 2)
key, err := builtins.StringOperand(k.Value, idx)
if err != nil {
return err
return builtins.NewOperandErr(2, "failed to stringify key %v at index %d: %v", k, idx, err)
}

switch key {
Expand All @@ -72,7 +72,7 @@ func builtinJSONMarshalWithOpts(_ BuiltinContext, operands []*ast.Term, iter fun
default:
prefixOpt, err := builtins.StringOperand(val.Value, idx)
if err != nil {
return builtins.NewOperandErr(2, "key %s contained invalid type: %v", key, err)
return builtins.NewOperandErr(2, "key %s failed cast to string: %v", key, err)
}
prefixWith = string(prefixOpt)
}
Expand All @@ -84,7 +84,7 @@ func builtinJSONMarshalWithOpts(_ BuiltinContext, operands []*ast.Term, iter fun
default:
indentOpt, err := builtins.StringOperand(val.Value, idx)
if err != nil {
return builtins.NewOperandErr(2, "key %s contained invalid type: %v", key, err)
return builtins.NewOperandErr(2, "key %s failed cast to string: %v", key, err)

}
indentWith = string(indentOpt)
Expand Down

0 comments on commit 0aa8987

Please sign in to comment.