Skip to content

Commit ef2146c

Browse files
authored
1 parent fc9e857 commit ef2146c

3 files changed

Lines changed: 27 additions & 13 deletions

File tree

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ require (
4646
github.com/speakeasy-api/huh v1.1.2
4747
github.com/speakeasy-api/jq v0.1.1-0.20251107233444-84d7e49e84a4
4848
github.com/speakeasy-api/openapi v1.20.0
49-
github.com/speakeasy-api/openapi-generation/v2 v2.879.10
49+
github.com/speakeasy-api/openapi-generation/v2 v2.879.11
5050
github.com/speakeasy-api/sdk-gen-config v1.56.0
5151
github.com/speakeasy-api/speakeasy-agent-mode-content v0.2.0
5252
github.com/speakeasy-api/speakeasy-client-sdk-go/v3 v3.26.7

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -548,8 +548,8 @@ github.com/speakeasy-api/libopenapi v0.21.9-fixhiddencomps-fixed h1:PL/kpBY5vkBm
548548
github.com/speakeasy-api/libopenapi v0.21.9-fixhiddencomps-fixed/go.mod h1:Gc8oQkjr2InxwumK0zOBtKN9gIlv9L2VmSVIUk2YxcU=
549549
github.com/speakeasy-api/openapi v1.20.0 h1:dfQaRL/1+NRPho/CnG0McONceyam7HrWJnpU7mwz570=
550550
github.com/speakeasy-api/openapi v1.20.0/go.mod h1:5gOzfAL1nSm57JswBgbpLqoBMGFlabSlTbxTNgHHO/0=
551-
github.com/speakeasy-api/openapi-generation/v2 v2.879.10 h1:xMsXqOHi1TtSxSwpjWu0n9eBb1ASuJFLsjtfw8ErclE=
552-
github.com/speakeasy-api/openapi-generation/v2 v2.879.10/go.mod h1:v+LnvSXKaS5XX5ub75L5kRXbKu7UMrPXbSwY6n1/Aoc=
551+
github.com/speakeasy-api/openapi-generation/v2 v2.879.11 h1:qcZF2Kkm6CC7K353ORQ2Ki1tYqA2hPKK0YnAKgrlawU=
552+
github.com/speakeasy-api/openapi-generation/v2 v2.879.11/go.mod h1:v+LnvSXKaS5XX5ub75L5kRXbKu7UMrPXbSwY6n1/Aoc=
553553
github.com/speakeasy-api/openapi/openapi/linter/customrules v0.0.0-20260206023826-2483fb8e98b4 h1:gV+lYeVNNJG9X3Sl9Su3cRh1iF/oNqzvb5Ijq2QR8jY=
554554
github.com/speakeasy-api/openapi/openapi/linter/customrules v0.0.0-20260206023826-2483fb8e98b4/go.mod h1:1zQpVio7X6QJDtyNdUguCgZ+IC7CzKhhjvNgJdvGVF0=
555555
github.com/speakeasy-api/sdk-gen-config v1.56.0 h1:1tVW8mV/7o9/iFwHd7cGGZ7UCxCcU12QN9zOMwb/zCI=

internal/sdkgen/sdkgen.go

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,10 @@ func Generate(ctx context.Context, opts GenerateOptions) (*GenerationAccess, err
188188
}
189189

190190
// Track the current generation step for error reporting
191-
failedStepMessage := ""
191+
var failedStep *generate.ProgressStep
192192
trackProgress := func(update generate.ProgressUpdate) {
193193
if update.Step != nil {
194-
failedStepMessage = update.Step.Message
194+
failedStep = update.Step
195195
}
196196
// Forward to user-provided callback if present
197197
if opts.StreamableGeneration != nil && opts.StreamableGeneration.OnProgressUpdate != nil {
@@ -276,18 +276,16 @@ func Generate(ctx context.Context, opts GenerateOptions) (*GenerationAccess, err
276276

277277
if len(errs) > 0 {
278278
for _, err := range errs {
279-
// Check if it's a ConflictsError - render pretty conflict message
280-
var conflictErr *merge.ConflictsError
281-
if stderrors.As(err, &conflictErr) {
282-
renderConflictsError(logger, conflictErr)
283-
// Don't log the generic error for conflicts - we rendered a nice message
284-
continue
279+
280+
if pe := handlePersistentEditsError(logger, err); pe != nil {
281+
return fmt.Errorf("could not apply persistent edits for %q: %w", opts.Language, pe)
285282
}
283+
286284
logger.Error("", zap.Error(err))
287285
}
288286

289-
if failedStepMessage != "" {
290-
return fmt.Errorf("generation failed for %q during step %q", opts.Language, failedStepMessage)
287+
if failedStep != nil {
288+
return fmt.Errorf("generation failed for %q during step %q", opts.Language, failedStep.Message)
291289
}
292290

293291
return fmt.Errorf("failed to generate %q", opts.Language)
@@ -372,6 +370,22 @@ func GetGenLockID(outDir string) *string {
372370
return nil
373371
}
374372

373+
// handlePersistentEditsError checks whether err is a persistent-edits failure.
374+
// If it is a ConflictsError, it renders the instructional message before returning it.
375+
// Returns nil if err is not a persistent-edits error.
376+
func handlePersistentEditsError(logger log.Logger, err error) error {
377+
var conflictErr *merge.ConflictsError
378+
if stderrors.As(err, &conflictErr) {
379+
renderConflictsError(logger, conflictErr)
380+
return conflictErr
381+
}
382+
var snapshotRefErr *merge.SnapshotRefError
383+
if stderrors.As(err, &snapshotRefErr) {
384+
return snapshotRefErr
385+
}
386+
return nil
387+
}
388+
375389
// renderConflictsError renders a git-status style error message for merge conflicts.
376390
func renderConflictsError(logger log.Logger, conflictErr *merge.ConflictsError) {
377391
// Build file list with "both modified:" prefix like git status

0 commit comments

Comments
 (0)