From 397985f1ae421a7facd0e83b4261eaa5c91c1729 Mon Sep 17 00:00:00 2001 From: lash Date: Thu, 6 Apr 2023 12:47:09 +0100 Subject: [PATCH] Add descriptive input checker error --- go/engine/engine.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/go/engine/engine.go b/go/engine/engine.go index aeb34e9..c883423 100644 --- a/go/engine/engine.go +++ b/go/engine/engine.go @@ -13,7 +13,8 @@ import ( ) var ( - inputRegex = regexp.MustCompile("^[a-zA-Z0-9].*$") + inputRegexStr = "^[a-zA-Z0-9].*$" + inputRegex = regexp.MustCompile(inputRegexStr) ) // //type Config struct { @@ -50,9 +51,10 @@ func(en *Engine) Init(sym string, ctx context.Context) error { return nil } +// return descriptive error if client input is invalid func checkInput(input []byte) error { if !inputRegex.Match(input) { - return fmt.Errorf("Invalid input format: %s", input) + return fmt.Errorf("Input '%s' does not match format /%s/", input, inputRegexStr) } return nil } @@ -70,12 +72,13 @@ func checkInput(input []byte) error { func (en *Engine) Exec(input []byte, ctx context.Context) (bool, error) { err := checkInput(input) if err != nil { - return false, err + return true, err } err = en.st.SetInput(input) if err != nil { return false, err } + log.Printf("new execution with input '%s' (0x%x)", input, input) code, err := en.st.GetCode() if err != nil {