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