Skip to content

Commit

Permalink
Refactor PrintException function in V8 runtime to improve error repor…
Browse files Browse the repository at this point in the history
…ting; ensure stack trace is displayed in debug mode and streamline exception handling for better clarity.
  • Loading branch information
trheyi committed Dec 14, 2024
1 parent 955d56a commit b161b13
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions runtime/v8/sourcemap.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,14 @@ func clearSourceMaps() {

// PrintException print the exception
func PrintException(method string, args []interface{}, jserr *v8go.JSError, rootMapping interface{}) {
ex := exception.New(jserr.Message, 500)
color.Red("\n----------------------------------")
color.Red("Script Exception: %s", fmt.Sprintf("%d %s", ex.Code, ex.Message))
color.Red("----------------------------------")

color.Red("%s\n", StackTrace(jserr, rootMapping))
if runtimeOption.Debug {
ex := exception.New(jserr.Message, 500)
color.Red("\n----------------------------------")
color.Red("Script Exception: %s", fmt.Sprintf("%d %s", ex.Code, ex.Message))
color.Red("----------------------------------")

color.Red("%s\n", StackTrace(jserr, rootMapping))
fmt.Println(color.YellowString("\nMethod:"), color.WhiteString("%s", method))
color.Yellow("Args:")
raw, _ := jsoniter.MarshalToString(args)
Expand All @@ -88,11 +89,6 @@ func StackTrace(jserr *v8go.JSError, rootMapping interface{}) string {

ex := exception.New(jserr.Message, 500)

// Production mode will not show the stack trace
if runtimeOption.Debug == false {
return fmt.Sprintf("%d %s", ex.Code, ex.Message)
}

// Development mode will show the stack trace
entries := parseStackTrace(jserr.StackTrace)
if entries == nil || len(entries) == 0 {
Expand Down

0 comments on commit b161b13

Please sign in to comment.