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 /internal/jsre/pretty.go | |
parent | ffaf58f0a98bd987bbe76e8669bb22c405dcd62a (diff) | |
download | dexon-14ae5708d61059d424c9be9822b85a3f4bb392b3.tar.gz dexon-14ae5708d61059d424c9be9822b85a3f4bb392b3.tar.zst dexon-14ae5708d61059d424c9be9822b85a3f4bb392b3.zip |
console, internal/jsre: colorize JavaScript exceptions too
Diffstat (limited to 'internal/jsre/pretty.go')
-rw-r--r-- | internal/jsre/pretty.go | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/internal/jsre/pretty.go b/internal/jsre/pretty.go index cf4bf2cf8..30d8660ff 100644 --- a/internal/jsre/pretty.go +++ b/internal/jsre/pretty.go @@ -37,6 +37,7 @@ var ( SpecialColor = color.New(color.Bold).SprintfFunc() NumberColor = color.New(color.FgRed).SprintfFunc() StringColor = color.New(color.FgGreen).SprintfFunc() + ErrorColor = color.New(color.FgHiRed).SprintfFunc() ) // these fields are hidden when printing objects. @@ -55,6 +56,23 @@ func prettyPrint(vm *otto.Otto, value otto.Value, w io.Writer) { ppctx{vm: vm, w: w}.printValue(value, 0, false) } +// prettyError writes err to standard output. +func prettyError(vm *otto.Otto, err error, w io.Writer) { + failure := err.Error() + if ottoErr, ok := err.(*otto.Error); ok { + failure = ottoErr.String() + } + fmt.Fprint(w, ErrorColor("%s", failure)) +} + +// 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() +} + func prettyPrintJS(call otto.FunctionCall, w io.Writer) otto.Value { for _, v := range call.ArgumentList { prettyPrint(call.Otto, v, w) |