@@ -13,10 +13,17 @@ import {convertPipeline, type ConvertResult} from '@salesforce/b2c-tooling-sdk/o
1313import { glob } from 'glob' ;
1414import { t } from '../../i18n/index.js' ;
1515
16+ interface ConvertError {
17+ pipelineName : string ;
18+ error : string ;
19+ }
20+
1621interface ConvertResponse {
1722 results : ConvertResult [ ] ;
23+ errors : ConvertError [ ] ;
1824 totalPipelines : number ;
1925 successCount : number ;
26+ failureCount : number ;
2027 warningCount : number ;
2128}
2229
@@ -78,8 +85,10 @@ export default class PipelineConvert extends BaseCommand<typeof PipelineConvert>
7885
7986 const response : ConvertResponse = {
8087 results : conversionResults . results ,
88+ errors : conversionResults . errors ,
8189 totalPipelines : inputFiles . length ,
8290 successCount : conversionResults . successCount ,
91+ failureCount : conversionResults . failureCount ,
8392 warningCount : conversionResults . warningCount ,
8493 } ;
8594
@@ -89,12 +98,26 @@ export default class PipelineConvert extends BaseCommand<typeof PipelineConvert>
8998
9099 if ( ! dryRun ) {
91100 this . log ( '' ) ;
92- this . log (
93- t ( 'commands.pipeline.convert.summary' , 'Converted {{count}} pipeline(s) with {{warnings}} warning(s)' , {
94- count : conversionResults . successCount ,
95- warnings : conversionResults . warningCount ,
96- } ) ,
97- ) ;
101+ if ( conversionResults . failureCount > 0 ) {
102+ this . log (
103+ t (
104+ 'commands.pipeline.convert.summaryWithFailures' ,
105+ 'Converted {{success}} pipeline(s), {{failures}} failed, {{warnings}} warning(s)' ,
106+ {
107+ success : conversionResults . successCount ,
108+ failures : conversionResults . failureCount ,
109+ warnings : conversionResults . warningCount ,
110+ } ,
111+ ) ,
112+ ) ;
113+ } else {
114+ this . log (
115+ t ( 'commands.pipeline.convert.summary' , 'Converted {{count}} pipeline(s) with {{warnings}} warning(s)' , {
116+ count : conversionResults . successCount ,
117+ warnings : conversionResults . warningCount ,
118+ } ) ,
119+ ) ;
120+ }
98121 }
99122
100123 return response ;
@@ -107,7 +130,7 @@ export default class PipelineConvert extends BaseCommand<typeof PipelineConvert>
107130 inputFile : string ,
108131 output : string | undefined ,
109132 dryRun : boolean ,
110- ) : Promise < { result : ConvertResult ; success : boolean } > {
133+ ) : Promise < { result ? : ConvertResult ; success : boolean ; error ?: ConvertError } > {
111134 const pipelineName = basename ( inputFile , '.xml' ) ;
112135
113136 if ( ! dryRun ) {
@@ -125,37 +148,52 @@ export default class PipelineConvert extends BaseCommand<typeof PipelineConvert>
125148 ? join ( output , `${ pipelineName } .js` )
126149 : join ( dirname ( inputFile ) , `${ pipelineName } .js` ) ;
127150
128- const result = await this . operations . convertPipeline ( inputFile , {
129- outputPath,
130- dryRun,
131- } ) ;
151+ try {
152+ const result = await this . operations . convertPipeline ( inputFile , {
153+ outputPath,
154+ dryRun,
155+ } ) ;
132156
133- if ( result . warnings . length > 0 ) {
134- for ( const warning of result . warnings ) {
135- this . warn ( warning ) ;
157+ if ( result . warnings . length > 0 ) {
158+ for ( const warning of result . warnings ) {
159+ this . warn ( warning ) ;
160+ }
136161 }
137- }
138162
139- let success = false ;
140- if ( dryRun ) {
141- // In dry-run mode, output the generated code
142- if ( ! this . jsonEnabled ( ) ) {
143- ux . stdout ( `\n// === ${ pipelineName } .js ===\n` ) ;
144- ux . stdout ( result . code ) ;
145- ux . stdout ( '\n' ) ;
163+ let success = false ;
164+ if ( dryRun ) {
165+ // In dry-run mode, output the generated code
166+ if ( ! this . jsonEnabled ( ) ) {
167+ ux . stdout ( `\n// === ${ pipelineName } .js ===\n` ) ;
168+ ux . stdout ( result . code ) ;
169+ ux . stdout ( '\n' ) ;
170+ }
171+ success = true ;
172+ } else if ( outputPath ) {
173+ // Write the file
174+ await writeFile ( outputPath , result . code , 'utf8' ) ;
175+ this . log (
176+ t ( 'commands.pipeline.convert.generated' , 'Generated: {{path}}' , {
177+ path : outputPath ,
178+ } ) ,
179+ ) ;
180+ success = true ;
146181 }
147- } else if ( outputPath ) {
148- // Write the file
149- await writeFile ( outputPath , result . code , 'utf8' ) ;
150- this . log (
151- t ( 'commands.pipeline.convert.generated' , 'Generated: {{path}}' , {
152- path : outputPath ,
182+
183+ return { result, success} ;
184+ } catch ( err ) {
185+ const errorMessage = err instanceof Error ? err . message : String ( err ) ;
186+ this . logToStderr (
187+ t ( 'commands.pipeline.convert.failed' , 'Failed to convert {{name}}: {{error}}' , {
188+ name : pipelineName ,
189+ error : errorMessage ,
153190 } ) ,
154191 ) ;
155- success = true ;
192+ return {
193+ success : false ,
194+ error : { pipelineName, error : errorMessage } ,
195+ } ;
156196 }
157-
158- return { result, success} ;
159197 }
160198
161199 /**
@@ -165,21 +203,37 @@ export default class PipelineConvert extends BaseCommand<typeof PipelineConvert>
165203 inputFiles : string [ ] ,
166204 output : string | undefined ,
167205 dryRun : boolean ,
168- ) : Promise < { results : ConvertResult [ ] ; successCount : number ; warningCount : number } > {
206+ ) : Promise < {
207+ results : ConvertResult [ ] ;
208+ errors : ConvertError [ ] ;
209+ successCount : number ;
210+ failureCount : number ;
211+ warningCount : number ;
212+ } > {
169213 const results : ConvertResult [ ] = [ ] ;
214+ const errors : ConvertError [ ] = [ ] ;
170215 let successCount = 0 ;
216+ let failureCount = 0 ;
171217 let warningCount = 0 ;
172218
173219 // Process files sequentially to maintain order and avoid concurrent file operations
174220 for ( const inputFile of inputFiles ) {
175221 // eslint-disable-next-line no-await-in-loop
176222 const fileResult = await this . processFile ( inputFile , output , dryRun ) ;
177- results . push ( fileResult . result ) ;
178- successCount += fileResult . success ? 1 : 0 ;
179- warningCount += fileResult . result . warnings . length ;
223+ if ( fileResult . result ) {
224+ results . push ( fileResult . result ) ;
225+ warningCount += fileResult . result . warnings . length ;
226+ }
227+ if ( fileResult . error ) {
228+ errors . push ( fileResult . error ) ;
229+ failureCount ++ ;
230+ }
231+ if ( fileResult . success ) {
232+ successCount ++ ;
233+ }
180234 }
181235
182- return { results, successCount, warningCount} ;
236+ return { results, errors , successCount, failureCount , warningCount} ;
183237 }
184238
185239 /**
0 commit comments