Skip to content

Commit 90a1b90

Browse files
committed
fix: Tweak the processing of the builder to handle how process.run returns
1 parent 0df70e1 commit 90a1b90

File tree

1 file changed

+64
-52
lines changed

1 file changed

+64
-52
lines changed

openapi-generator/lib/src/openapi_generator_runner.dart

Lines changed: 64 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class OpenapiGenerator extends GeneratorForAnnotation<annots.Openapi> {
2828
log: log,
2929
communication: OutputMessage(
3030
message: [
31+
'',
3132
' - :::::::::::::::::::::::::::::::::::::::::::',
3233
' - :: Openapi generator for dart ::',
3334
' - :::::::::::::::::::::::::::::::::::::::::::',
@@ -114,9 +115,11 @@ class OpenapiGenerator extends GeneratorForAnnotation<annots.Openapi> {
114115
{required FutureOr<List<String>> arguments}) async {
115116
final args = await arguments;
116117
logOutputMessage(
117-
log: log,
118-
communication:
119-
OutputMessage(message: 'OpenapiGenerator :: [${args.join(' ')}]'));
118+
log: log,
119+
communication: OutputMessage(
120+
message: 'OpenapiGenerator :: [ ${args.join(' ')} ]',
121+
),
122+
);
120123

121124
var binPath = (await Isolate.resolvePackageUri(
122125
Uri.parse('package:openapi_generator_cli/openapi-generator.jar')))!
@@ -125,30 +128,31 @@ class OpenapiGenerator extends GeneratorForAnnotation<annots.Openapi> {
125128
// Include java environment variables in openApiCliCommand
126129
var javaOpts = Platform.environment['JAVA_OPTS'] ?? '';
127130

128-
return await Process.run('java', [
131+
final result = await Process.run('java', [
129132
if (javaOpts.isNotEmpty) javaOpts,
130133
'-jar',
131134
"${"$binPath"}",
132135
...args,
133-
]).then(
134-
(value) => logOutputMessage(
136+
]);
137+
138+
if (result.exitCode != 0) {
139+
return Future.error(
140+
OutputMessage(
141+
message: ' - :: Codegen Failed. Generator output: ::',
142+
level: Level.SEVERE,
143+
additionalContext: result.stderr,
144+
stackTrace: StackTrace.current,
145+
),
146+
);
147+
} else {
148+
logOutputMessage(
135149
log: log,
136150
communication: OutputMessage(
137-
message: [value.stdout, ' - :: Codegen completed successfully. ::']
151+
message: [result.stdout, ' - :: Codegen completed successfully. ::']
138152
.join('\n'),
139153
),
140-
),
141-
onError: (e, st) => Future.error(
142-
Future.error(
143-
OutputMessage(
144-
message: ' - :: Codegen Failed. ::',
145-
level: Level.SEVERE,
146-
additionalContext: e,
147-
stackTrace: st,
148-
),
149-
),
150-
),
151-
);
154+
);
155+
}
152156
}
153157

154158
/// Next-gen of the generation.
@@ -292,27 +296,31 @@ class OpenapiGenerator extends GeneratorForAnnotation<annots.Openapi> {
292296
),
293297
);
294298

295-
return await Process.run(command.executable, command.arguments,
296-
runInShell: Platform.isWindows,
297-
workingDirectory: args.outputDirectory)
298-
.then(
299-
(v) => logOutputMessage(
299+
final results = await Process.run(
300+
command.executable,
301+
command.arguments,
302+
runInShell: Platform.isWindows,
303+
workingDirectory: args.outputDirectory,
304+
);
305+
306+
if (results.exitCode != 0) {
307+
return Future.error(
308+
OutputMessage(
309+
message:
310+
' - :: Failed to generate source code. Build Command output: ::',
311+
level: Level.SEVERE,
312+
additionalContext: results.stderr,
313+
stackTrace: StackTrace.current,
314+
),
315+
);
316+
} else {
317+
logOutputMessage(
300318
log: log,
301319
communication: OutputMessage(
302320
message: ' - :: Codegen completed successfully. ::',
303321
),
304-
),
305-
onError: (e, st) {
306-
return Future.error(
307-
OutputMessage(
308-
message: ' - :: Failed to generate source code. ::',
309-
level: Level.SEVERE,
310-
additionalContext: e,
311-
stackTrace: st,
312-
),
313-
);
314-
},
315-
);
322+
);
323+
}
316324
}
317325

318326
/// Conditionally fetches the dependencies in the newly generate library.
@@ -339,25 +347,29 @@ class OpenapiGenerator extends GeneratorForAnnotation<annots.Openapi> {
339347
),
340348
);
341349

342-
return await Process.run(command.executable, command.arguments,
343-
runInShell: Platform.isWindows,
344-
workingDirectory: args.outputDirectory)
345-
.then(
346-
(v) => logOutputMessage(
350+
final result = await Process.run(command.executable, command.arguments,
351+
runInShell: Platform.isWindows,
352+
workingDirectory: args.outputDirectory);
353+
if (result.exitCode != 0) {
354+
return Future.error(
355+
OutputMessage(
356+
message: ' - :: Install within generated sources failed. ::',
357+
level: Level.SEVERE,
358+
additionalContext: result.stderr,
359+
stackTrace: StackTrace.current,
360+
),
361+
);
362+
} else {
363+
logOutputMessage(
347364
log: log,
348365
communication: OutputMessage(
349-
message: [v.stdout, ' - :: Install completed successfully. ::']
350-
.join('\n'),
366+
message: [
367+
result.stdout,
368+
' - :: Install completed successfully. ::',
369+
].join('\n'),
351370
),
352-
),
353-
onError: (e, st) => Future.error(
354-
OutputMessage(
355-
message: ' - :: Install within generated sources failed. ::',
356-
level: Level.SEVERE,
357-
additionalContext: e,
358-
stackTrace: st),
359-
),
360-
);
371+
);
372+
}
361373
}
362374
}
363375

0 commit comments

Comments
 (0)