From 2eb84fc2b5f1207675d700c52052007a45d2f1f6 Mon Sep 17 00:00:00 2001 From: Lukasz Stefaniak Date: Wed, 9 Oct 2024 18:12:34 +0200 Subject: [PATCH] Do not panic and return exit code 0 even when errors happened --- cmd/root.go | 16 ++++++++-------- main.go | 2 +- process/helpers.go | 4 ++-- sqlmesh/health.go | 2 +- synq/synq.go | 8 ++++---- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index ede034f..c930e4d 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -54,7 +54,7 @@ var collectCmd = &cobra.Command{ }) if err != nil { fmt.Println(err) - os.Exit(1) + os.Exit(0) } }, } @@ -88,7 +88,7 @@ var uploadCmd = &cobra.Command{ }) if err != nil { fmt.Println(err) - os.Exit(1) + os.Exit(0) } }, } @@ -111,18 +111,18 @@ var uploadAuditCmd = &cobra.Command{ err := sqlmesh.CollectAuditLog(output, fileArg) if err != nil { logrus.WithError(err).Error("Failed to collect audit log") - os.Exit(1) + os.Exit(0) } } if SynqApiToken == "" { logrus.Error("SYNQ_TOKEN environment variable is not set") - os.Exit(1) + os.Exit(0) } if err := synq.UploadExecutionLog(cmd.Context(), output, SynqApiEndpoint, SynqApiToken); err != nil { logrus.WithError(err).Error("Failed to upload execution log") - os.Exit(1) + os.Exit(0) } }, } @@ -145,18 +145,18 @@ var uploadRunCmd = &cobra.Command{ err := sqlmesh.CollectAuditLog(output, fileArg) if err != nil { logrus.WithError(err).Error("Failed to collect audit log") - os.Exit(1) + os.Exit(0) } } if SynqApiToken == "" { logrus.Error("SYNQ_TOKEN environment variable is not set") - os.Exit(1) + os.Exit(0) } if err := synq.UploadExecutionLog(cmd.Context(), output, SynqApiEndpoint, SynqApiToken); err != nil { logrus.WithError(err).Error("Failed to upload execution log") - os.Exit(1) + os.Exit(0) } }, } diff --git a/main.go b/main.go index 046313e..d74f981 100644 --- a/main.go +++ b/main.go @@ -17,7 +17,7 @@ func main() { if err := cmd.Execute(); err != nil { logrus.WithError(err).Error("Error executing command") - os.Exit(1) + os.Exit(0) } os.Exit(0) } diff --git a/process/helpers.go b/process/helpers.go index e41c69d..e5b0e6f 100644 --- a/process/helpers.go +++ b/process/helpers.go @@ -52,12 +52,12 @@ func ExecuteCommand(ctx context.Context, cmdName string, args []string, opts ... stdOutReader, err := cmd.StdoutPipe() if err != nil { fmt.Fprintln(os.Stderr, "error creating StdoutPipe for Cmd", err) - os.Exit(1) + os.Exit(0) } stdErrReader, err := cmd.StderrPipe() if err != nil { fmt.Fprintln(os.Stderr, "error creating StderrPipe for Cmd", err) - os.Exit(1) + os.Exit(0) } var outb, errb bytes.Buffer diff --git a/sqlmesh/health.go b/sqlmesh/health.go index 1def626..bf66f8d 100644 --- a/sqlmesh/health.go +++ b/sqlmesh/health.go @@ -21,5 +21,5 @@ func WaitForSQLMeshToStart(url url.URL) { time.Sleep(1 * time.Second) } logrus.Error("SQLMesh did not start in time") - os.Exit(1) + os.Exit(0) } diff --git a/synq/synq.go b/synq/synq.go index 3038aa2..fce35ff 100644 --- a/synq/synq.go +++ b/synq/synq.go @@ -74,7 +74,7 @@ func UploadMetadata(ctx context.Context, output *ingestsqlmeshv1.IngestMetadataR oauthTokenSource, err := LongLivedTokenSource(token, parsedEndpoint) if err != nil { - panic(err) + return err } creds := credentials.NewTLS(&tls.Config{InsecureSkipVerify: false}) opts := []grpc.DialOption{ @@ -85,7 +85,7 @@ func UploadMetadata(ctx context.Context, output *ingestsqlmeshv1.IngestMetadataR conn, err := grpc.DialContext(ctx, grpcEndpoint(parsedEndpoint), opts...) if err != nil { - panic(err) + return err } defer conn.Close() @@ -106,7 +106,7 @@ func UploadExecutionLog(ctx context.Context, output *ingestsqlmeshv1.IngestExecu oauthTokenSource, err := LongLivedTokenSource(token, parsedEndpoint) if err != nil { - panic(err) + return err } creds := credentials.NewTLS(&tls.Config{InsecureSkipVerify: false}) opts := []grpc.DialOption{ @@ -117,7 +117,7 @@ func UploadExecutionLog(ctx context.Context, output *ingestsqlmeshv1.IngestExecu conn, err := grpc.DialContext(ctx, grpcEndpoint(parsedEndpoint), opts...) if err != nil { - panic(err) + return err } defer conn.Close()