Skip to content

Commit a9b6db1

Browse files
authored
feat: include the step which failed in error message (#1732)
1 parent ae90181 commit a9b6db1

File tree

1 file changed

+29
-11
lines changed

1 file changed

+29
-11
lines changed

internal/sdkgen/sdkgen.go

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -166,17 +166,34 @@ func Generate(ctx context.Context, opts GenerateOptions) (*GenerationAccess, err
166166
generatorOpts = append(generatorOpts, generate.WithSkipVersioning(opts.SkipVersioning))
167167
}
168168

169+
// Track the current generation step for error reporting
170+
var lastStepID generate.ProgressStepID
171+
trackProgress := func(update generate.ProgressUpdate) {
172+
if update.Step != nil {
173+
lastStepID = update.Step.ID
174+
}
175+
// Forward to user-provided callback if present
176+
if opts.StreamableGeneration != nil && opts.StreamableGeneration.OnProgressUpdate != nil {
177+
opts.StreamableGeneration.OnProgressUpdate(update)
178+
}
179+
}
180+
181+
// Enable step tracking by default for error reporting
182+
genSteps := true
183+
fileStatus := false
169184
if opts.StreamableGeneration != nil {
170-
generatorOpts = append(
171-
generatorOpts,
172-
generate.WithProgressUpdates(
173-
opts.TargetName,
174-
opts.StreamableGeneration.OnProgressUpdate,
175-
opts.StreamableGeneration.GenSteps,
176-
opts.StreamableGeneration.FileStatus,
177-
),
178-
)
185+
genSteps = opts.StreamableGeneration.GenSteps || true
186+
fileStatus = opts.StreamableGeneration.FileStatus
179187
}
188+
generatorOpts = append(
189+
generatorOpts,
190+
generate.WithProgressUpdates(
191+
opts.TargetName,
192+
trackProgress,
193+
genSteps,
194+
fileStatus,
195+
),
196+
)
180197

181198
g, err := generate.New(generatorOpts...)
182199
if err != nil {
@@ -197,7 +214,7 @@ func Generate(ctx context.Context, opts GenerateOptions) (*GenerationAccess, err
197214
var cancelled bool
198215
cancelled, errs = g.GenerateWithCancel(cancelCtx, schema, opts.SchemaPath, opts.Language, opts.OutDir, isRemote, opts.Compile)
199216
if cancelled {
200-
return fmt.Errorf("Generation was aborted for %s ✖", opts.Language)
217+
return fmt.Errorf("generation was aborted for %s ✖", opts.Language)
201218
}
202219
} else {
203220
errs = g.Generate(ctx, schema, opts.SchemaPath, opts.Language, opts.OutDir, isRemote, opts.Compile)
@@ -208,7 +225,8 @@ func Generate(ctx context.Context, opts GenerateOptions) (*GenerationAccess, err
208225
logger.Error("", zap.Error(err))
209226
}
210227

211-
return fmt.Errorf("failed to generate SDKs for %s ✖", opts.Language)
228+
stepMessage := generate.ProgressMessages[lastStepID]
229+
return fmt.Errorf("failed to generate %q: step failed: %s", opts.Language, stepMessage)
212230
}
213231

214232
return nil

0 commit comments

Comments
 (0)