Skip to content

Commit

Permalink
style(cdk): detect lwcomponent error inside Execute() (#1001)
Browse files Browse the repository at this point in the history
  • Loading branch information
afiune authored Nov 2, 2022
1 parent 363c1d4 commit 5f88e52
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
6 changes: 6 additions & 0 deletions cli/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/spf13/cobra"
"github.com/spf13/viper"

"github.com/lacework/go-sdk/lwcomponent"
"github.com/lacework/go-sdk/lwlogger"
)

Expand Down Expand Up @@ -107,6 +108,11 @@ func Execute() (err error) {
exitwithCode(err, err.ExitCode)
case *queryFailonError:
exitwithCode(err, err.ExitCode)
case *lwcomponent.RunError:
// by default, all our components should display the error to
// the end user, which is why we don't output it, but we still
// exit the main program with the exit code from the component
os.Exit(err.ExitCode)
}
}()
defer cli.Wait()
Expand Down
8 changes: 0 additions & 8 deletions cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,10 @@ import (
"os"

"github.com/lacework/go-sdk/cli/cmd"
"github.com/lacework/go-sdk/lwcomponent"
)

func main() {
if err := cmd.Execute(); err != nil {
if componentError, ok := err.(*lwcomponent.RunError); ok {
// by default, all our components should display the error
// to the end user, which is why we don't output it, but we
// still exit the main program with the exit code from the component
os.Exit(componentError.ExitCode)
}

fmt.Fprintf(os.Stderr, "ERROR %s\n", err)
os.Exit(1)
}
Expand Down

0 comments on commit 5f88e52

Please sign in to comment.