github.com/goccy/go-json@v0.10.3-0.20240509105655-5e2ae3f23c1d/internal/encoder/vm/debug_vm.go (about) 1 package vm 2 3 import ( 4 "fmt" 5 "io" 6 7 "github.com/goccy/go-json/internal/encoder" 8 ) 9 10 func DebugRun(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]byte, error) { 11 defer func() { 12 var code *encoder.Opcode 13 if (ctx.Option.Flag & encoder.HTMLEscapeOption) != 0 { 14 code = codeSet.EscapeKeyCode 15 } else { 16 code = codeSet.NoescapeKeyCode 17 } 18 if wc := ctx.Option.DebugDOTOut; wc != nil { 19 _, _ = io.WriteString(wc, code.DumpDOT()) 20 wc.Close() 21 ctx.Option.DebugDOTOut = nil 22 } 23 24 if err := recover(); err != nil { 25 w := ctx.Option.DebugOut 26 fmt.Fprintln(w, "=============[DEBUG]===============") 27 fmt.Fprintln(w, "* [TYPE]") 28 fmt.Fprintln(w, codeSet.Type) 29 fmt.Fprintf(w, "\n") 30 fmt.Fprintln(w, "* [ALL OPCODE]") 31 fmt.Fprintln(w, code.Dump()) 32 fmt.Fprintf(w, "\n") 33 fmt.Fprintln(w, "* [CONTEXT]") 34 fmt.Fprintf(w, "%+v\n", ctx) 35 fmt.Fprintln(w, "===================================") 36 panic(err) 37 } 38 }() 39 40 return Run(ctx, b, codeSet) 41 }