diff options
| author | Aleksandr Nogikh <nogikh@google.com> | 2024-01-02 12:54:07 +0100 |
|---|---|---|
| committer | Aleksandr Nogikh <nogikh@google.com> | 2024-02-19 11:54:01 +0000 |
| commit | 033d9b88e6a8e1257e1733bb0ae632836f3116b0 (patch) | |
| tree | 030e47e3606a73f0dd62a544a0bbe2157903612d /prog/encoding.go | |
| parent | 51bd59d51b748227985e5209ef66114956773148 (diff) | |
prog: highlight error location
Simplify seed program debugging by highlighting the actual error
location in the source text.
Diffstat (limited to 'prog/encoding.go')
| -rw-r--r-- | prog/encoding.go | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/prog/encoding.go b/prog/encoding.go index 6d7daeacb..cd4eef17f 100644 --- a/prog/encoding.go +++ b/prog/encoding.go @@ -457,7 +457,7 @@ func (p *parser) parseArgImpl(typ Type, dir Dir) (Arg, error) { return p.parseAuto(typ, dir) default: return nil, fmt.Errorf("failed to parse argument at '%c' (line #%v/%v: %v)", - p.Char(), p.l, p.i, p.s) + p.Char(), p.l, p.i, highlightError(p.s, p.i)) } } @@ -1261,7 +1261,8 @@ func (p *parser) Ident() string { func (p *parser) failf(msg string, args ...interface{}) { if p.e == nil { - p.e = fmt.Errorf("%v\nline #%v:%v: %v", fmt.Sprintf(msg, args...), p.l, p.i, p.s) + p.e = fmt.Errorf("%v\nline #%v:%v: %v", fmt.Sprintf(msg, args...), p.l, p.i, + highlightError(p.s, p.i)) } } @@ -1311,3 +1312,7 @@ func CallSet(data []byte) (map[string]struct{}, int, error) { } return calls, ncalls, nil } + +func highlightError(s string, offset int) string { + return s[:offset] + "<<<!!ERROR!!>>>" + s[offset:] +} |
