Skip to content

Commit 459ffe3

Browse files
committed
cmd/ie/commands/test: Propagate error instead of exiting
Signed-off-by: Jose Blanquicet <josebl@microsoft.com>
1 parent 5291a2c commit 459ffe3

1 file changed

Lines changed: 10 additions & 12 deletions

File tree

cmd/ie/commands/test.go

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
package commands
22

33
import (
4+
"errors"
45
"fmt"
5-
"os"
66

77
"github.com/Azure/InnovationEngine/internal/engine"
8-
"github.com/Azure/InnovationEngine/internal/logging"
98
"github.com/spf13/cobra"
109
)
1110

@@ -22,11 +21,10 @@ var testCommand = &cobra.Command{
2221
Use: "test [markdown file]",
2322
Args: cobra.MinimumNArgs(1),
2423
Short: "Test document commands against it's expected outputs.",
25-
Run: func(cmd *cobra.Command, args []string) {
24+
RunE: func(cmd *cobra.Command, args []string) error {
2625
markdownFile := args[0]
2726
if markdownFile == "" {
28-
cmd.Help()
29-
return
27+
return errors.New("no markdown file specified")
3028
}
3129

3230
verbose, _ := cmd.Flags().GetBool("verbose")
@@ -39,9 +37,7 @@ var testCommand = &cobra.Command{
3937
CorrelationId: "",
4038
})
4139
if err != nil {
42-
logging.GlobalLogger.Errorf("Error creating engine %s", err)
43-
fmt.Printf("Error creating engine %s", err)
44-
os.Exit(1)
40+
return fmt.Errorf("creating engine: %w", err)
4541
}
4642

4743
scenario, err := engine.CreateScenarioFromMarkdown(
@@ -50,11 +46,13 @@ var testCommand = &cobra.Command{
5046
nil,
5147
)
5248
if err != nil {
53-
logging.GlobalLogger.Errorf("Error creating scenario %s", err)
54-
fmt.Printf("Error creating engine %s", err)
55-
os.Exit(1)
49+
return fmt.Errorf("creating scenario: %w", err)
5650
}
5751

58-
innovationEngine.TestScenario(scenario)
52+
if err := innovationEngine.TestScenario(scenario); err != nil {
53+
return fmt.Errorf("testing scenario: %w", err)
54+
}
55+
56+
return nil
5957
},
6058
}

0 commit comments

Comments
 (0)