Skip to content

Commit

Permalink
[engine] Include arguments in emit errors
Browse files Browse the repository at this point in the history
This will make debugging slightly easier when encountering these errors.

Change-Id: Ie9c671889c715dd64fb045aed057d451c437cd13
Reviewed-on: https://fuchsia-review.googlesource.com/c/shac-project/shac/+/931036
Fuchsia-Auto-Submit: Oliver Newman <olivernewman@google.com>
Reviewed-by: Ina Huh <ihuh@google.com>
Commit-Queue: Oliver Newman <olivernewman@google.com>
  • Loading branch information
orn688 authored and CQ Bot committed Oct 16, 2023
1 parent d9d4a62 commit 308e502
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions internal/engine/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1528,7 +1528,7 @@ func TestTestDataFailOrThrow(t *testing.T) {
},
{
"ctx-emit-finding-end_col-col-equal.star",
"ctx.emit.finding: for parameter \"end_col\": must be greater than \"col\"",
"ctx.emit.finding: for parameter \"end_col\": \"end_col\" (2) must be greater than \"col\" (2)",
" //ctx-emit-finding-end_col-col-equal.star:16:21: in cb\n",
},
{
Expand All @@ -1543,7 +1543,7 @@ func TestTestDataFailOrThrow(t *testing.T) {
},
{
"ctx-emit-finding-end_line-line-reverse.star",
"ctx.emit.finding: for parameter \"end_line\": must be greater than or equal to \"line\"",
"ctx.emit.finding: for parameter \"end_line\": \"end_line\" (1) must be greater than or equal to \"line\" (2)",
" //ctx-emit-finding-end_line-line-reverse.star:16:21: in cb\n",
},
{
Expand Down
4 changes: 2 additions & 2 deletions internal/engine/runtime_ctx_emit.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ func ctxEmitFinding(ctx context.Context, s *shacState, name string, args starlar
}
if span.End.Line > 0 {
if span.End.Line < span.Start.Line {
return errors.New("for parameter \"end_line\": must be greater than or equal to \"line\"")
return fmt.Errorf("for parameter \"end_line\": \"end_line\" (%d) must be greater than or equal to \"line\" (%d)", span.End.Line, span.Start.Line)
} else if span.End.Line == span.Start.Line && span.End.Col > 0 && span.End.Col <= span.Start.Col {
return errors.New("for parameter \"end_col\": must be greater than \"col\"")
return fmt.Errorf("for parameter \"end_col\": \"end_col\" (%d) must be greater than \"col\" (%d)", span.End.Col, span.Start.Col)
}
} else if span.End.Col > 0 {
// If end_col is set but end_line is unset, assume that end_line is
Expand Down

0 comments on commit 308e502

Please sign in to comment.