@@ -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