Skip to content

Commit

Permalink
fix: properly return run error if studio wasn't launched (#946)
Browse files Browse the repository at this point in the history
  • Loading branch information
chase-crumbaugh committed Sep 16, 2024
1 parent bd694e7 commit 65ee8ef
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ func runNonInteractive(ctx context.Context, flags RunFlags) error {

err = workflow.Run(ctx)

// We don't return the error here because we want to try to launch the studio to help fix the issue, if possible
if err != nil {
log.From(ctx).Error(err.Error())
}
Expand All @@ -331,7 +332,11 @@ func runNonInteractive(ctx context.Context, flags RunFlags) error {

github.GenerateWorkflowSummary(ctx, workflow.RootStep)

return maybeLaunchStudio(ctx, workflow, flags)
if studioErr, studioLaunched := maybeLaunchStudio(ctx, workflow, flags); !studioLaunched {
return err // Now return the original error if we didn't launch the studio
} else {
return studioErr
}
}

func runInteractive(ctx context.Context, flags RunFlags) error {
Expand Down Expand Up @@ -389,24 +394,29 @@ func runInteractive(ctx context.Context, flags RunFlags) error {
workflow.RootStep.Finalize(err == nil)
}

// We don't return the error here because we want to try to launch the studio to help fix the issue, if possible
if err != nil {
log.From(ctx).Error(err.Error())
} else {
workflow.PrintSuccessSummary(ctx)
}

return maybeLaunchStudio(ctx, workflow, flags)
if studioErr, studioLaunched := maybeLaunchStudio(ctx, workflow, flags); !studioLaunched {
return err // Now return the original error if we didn't launch the studio
} else {
return studioErr
}
}

func maybeLaunchStudio(ctx context.Context, wf *run.Workflow, flags RunFlags) error {
func maybeLaunchStudio(ctx context.Context, wf *run.Workflow, flags RunFlags) (error, bool) {
canLaunch, numDiagnostics := studio.CanLaunch(ctx, wf)
if canLaunch && flags.Watch {
return studio.LaunchStudio(ctx, wf)
return studio.LaunchStudio(ctx, wf), true
} else if numDiagnostics > 1 {
log.From(ctx).PrintfStyled(styles.Info, "\nWe've detected `%d` potential improvements for your SDK.\nGet automatic fixes in the Studio with `speakeasy run --watch`", numDiagnostics)
} else if numDiagnostics == 1 {
log.From(ctx).PrintfStyled(styles.Info, "\nWe've detected `1` potential improvement for your SDK.\nGet automatic fixes in the Studio with `speakeasy run --watch`")
}

return nil
return nil, false
}

0 comments on commit 65ee8ef

Please sign in to comment.