Skip to content

Commit

Permalink
Do not panic and return exit code 0 even when errors happened
Browse files Browse the repository at this point in the history
  • Loading branch information
lustefaniak committed Oct 9, 2024
1 parent 760886b commit 2eb84fc
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 16 deletions.
16 changes: 8 additions & 8 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ var collectCmd = &cobra.Command{
})
if err != nil {
fmt.Println(err)
os.Exit(1)
os.Exit(0)
}
},
}
Expand Down Expand Up @@ -88,7 +88,7 @@ var uploadCmd = &cobra.Command{
})
if err != nil {
fmt.Println(err)
os.Exit(1)
os.Exit(0)
}
},
}
Expand All @@ -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)
}
},
}
Expand All @@ -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)
}
},
}
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
4 changes: 2 additions & 2 deletions process/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion sqlmesh/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
8 changes: 4 additions & 4 deletions synq/synq.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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()

Expand All @@ -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{
Expand All @@ -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()

Expand Down

0 comments on commit 2eb84fc

Please sign in to comment.