From 033d9b88e6a8e1257e1733bb0ae632836f3116b0 Mon Sep 17 00:00:00 2001 From: Aleksandr Nogikh Date: Tue, 2 Jan 2024 12:54:07 +0100 Subject: prog: highlight error location Simplify seed program debugging by highlighting the actual error location in the source text. --- prog/encoding.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'prog/encoding.go') 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] + "<<>>" + s[offset:] +} -- cgit mrf-deployment