diff options
author | Péter Szilágyi <peterke@gmail.com> | 2016-05-11 22:28:29 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2016-05-30 22:25:23 +0800 |
commit | 14ae5708d61059d424c9be9822b85a3f4bb392b3 (patch) | |
tree | d5d29a92448808718dac4b6ebd967480656dc7df /console/console.go | |
parent | ffaf58f0a98bd987bbe76e8669bb22c405dcd62a (diff) | |
download | go-tangerine-14ae5708d61059d424c9be9822b85a3f4bb392b3.tar.gz go-tangerine-14ae5708d61059d424c9be9822b85a3f4bb392b3.tar.zst go-tangerine-14ae5708d61059d424c9be9822b85a3f4bb392b3.zip |
console, internal/jsre: colorize JavaScript exceptions too
Diffstat (limited to 'console/console.go')
-rw-r--r-- | console/console.go | 15 |
1 files changed, 5 insertions, 10 deletions
diff --git a/console/console.go b/console/console.go index 37c9f0afa..d10353093 100644 --- a/console/console.go +++ b/console/console.go @@ -182,7 +182,11 @@ func (c *Console) init(preload []string) error { // Preload any JavaScript files before starting the console for _, path := range preload { if err := c.jsre.Exec(path); err != nil { - return fmt.Errorf("%s: %v", path, jsErrorString(err)) + failure := err.Error() + if ottoErr, ok := err.(*otto.Error); ok { + failure = ottoErr.String() + } + return fmt.Errorf("%s: %v", path, failure) } } // Configure the console's input prompter for scrollback and tab completion @@ -269,7 +273,6 @@ func (c *Console) Evaluate(statement string) error { } }() if err := c.jsre.Evaluate(statement, c.printer); err != nil { - fmt.Fprintf(c.printer, "%v\n", jsErrorString(err)) return err } return nil @@ -359,11 +362,3 @@ func (c *Console) Stop(graceful bool) error { c.jsre.Stop(graceful) return nil } - -// jsErrorString adds a backtrace to errors generated by otto. -func jsErrorString(err error) string { - if ottoErr, ok := err.(*otto.Error); ok { - return ottoErr.String() - } - return err.Error() -} |