From c371888daaad2d5fd82e0552164005515a8056ee Mon Sep 17 00:00:00 2001 From: Dusty Pianalto Date: Sun, 19 Apr 2020 17:20:44 -0800 Subject: [PATCH] Update p command to use error channel --- djpianalto.com/goff/exts/P_interpreter.go | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/djpianalto.com/goff/exts/P_interpreter.go b/djpianalto.com/goff/exts/P_interpreter.go index ddacead..57f4b77 100644 --- a/djpianalto.com/goff/exts/P_interpreter.go +++ b/djpianalto.com/goff/exts/P_interpreter.go @@ -7,7 +7,7 @@ import ( "strings" ) -func pCommand(ctx disgoman.Context, args []string) error { +func pCommand(ctx disgoman.Context, args []string) { input := strings.Join(args, "") const LENGTH = 1999 var mem [LENGTH]byte @@ -57,8 +57,12 @@ func pCommand(ctx disgoman.Context, args []string) error { } } } else { - ctx.Send(fmt.Sprintf("Invalid Character: %v", input[i])) - return errors.New("invalid character") + ctx.ErrorChannel <- disgoman.CommandError{ + Context: ctx, + Message: fmt.Sprintf("Invalid Character: %v", input[i]), + Error: errors.New("invalid character"), + } + return } } var out []byte @@ -67,11 +71,14 @@ func pCommand(ctx disgoman.Context, args []string) error { out = append(out, i) } } - fmt.Println(out) _, err := ctx.Send(string(out)) if err != nil { - fmt.Println(err) - return err + ctx.ErrorChannel <- disgoman.CommandError{ + Context: ctx, + Message: "Couldn't send results", + Error: err, + } + return } - return nil + return }