github.com/3JoB/go-json@v0.10.4/internal/encoder/vm_color/debug_vm.go (about) 1 package vm_color 2 3 import ( 4 "fmt" 5 6 "github.com/3JoB/go-json/internal/encoder" 7 ) 8 9 func DebugRun(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]byte, error) { 10 var code *encoder.Opcode 11 if (ctx.Option.Flag & encoder.HTMLEscapeOption) != 0 { 12 code = codeSet.EscapeKeyCode 13 } else { 14 code = codeSet.NoescapeKeyCode 15 } 16 17 defer func() { 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.Fprint(w, "\n") 24 fmt.Fprintln(w, "* [ALL OPCODE]") 25 fmt.Fprintln(w, code.Dump()) 26 fmt.Fprint(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 }