From f4408fe641e4b0e27c168bcc9bbc4f69937cefc8 Mon Sep 17 00:00:00 2001 From: Philipp Tanlak Date: Sun, 27 Aug 2023 18:04:07 +0200 Subject: improve error logging --- js.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'js.go') diff --git a/js.go b/js.go index 242f15f..6be1461 100644 --- a/js.go +++ b/js.go @@ -14,6 +14,16 @@ import ( v8 "rogchap.com/v8go" ) +type TransformError struct { + Line int + Column int + Text string +} + +func (err TransformError) Error() string { + return fmt.Sprintf("%d:%d: %s", err.Line, err.Column, err.Text) +} + func init() { rand.Seed(time.Now().UnixNano()) } @@ -34,7 +44,12 @@ func build(src string) (string, error) { var errs []error for _, msg := range res.Errors { - errs = append(errs, fmt.Errorf("%s", msg.Text)) + err := TransformError{Text: msg.Text} + if msg.Location != nil { + err.Line = msg.Location.Line + err.Column = msg.Location.Column + } + errs = append(errs, err) } if len(res.Errors) > 0 { return "", errors.Join(errs...) -- cgit v1.2.3