From 806c9b38dc3afe82ea5b03fc589bcaaabdeb6630 Mon Sep 17 00:00:00 2001 From: Felix Angelov Date: Tue, 11 Mar 2025 11:35:24 -0500 Subject: [PATCH] feat(shorebird_cli): improve artifact build failure messages (#2949) --- .../artifact_builder/artifact_builder.dart | 47 +++++++++++++------ .../artifact_builder_test.dart | 15 ++++-- 2 files changed, 45 insertions(+), 17 deletions(-) diff --git a/packages/shorebird_cli/lib/src/artifact_builder/artifact_builder.dart b/packages/shorebird_cli/lib/src/artifact_builder/artifact_builder.dart index 3d767ec9..1eed1f95 100644 --- a/packages/shorebird_cli/lib/src/artifact_builder/artifact_builder.dart +++ b/packages/shorebird_cli/lib/src/artifact_builder/artifact_builder.dart @@ -141,7 +141,10 @@ class ArtifactBuilder { final exitCode = await buildProcess.exitCode; if (exitCode != ExitCode.success.code) { throw ArtifactBuildException( - 'Failed to build', + ''' +Failed to build AAB. +Command: $executable ${arguments.join(' ')} +Reason: Exited with code $exitCode.''', stderr: stderrLines, stdout: stdoutLines, ); @@ -208,10 +211,10 @@ class ArtifactBuilder { ); if (result.exitCode != ExitCode.success.code) { - throw ArtifactBuildException.fromProcessResult( - 'Failed to build', - buildProcessResult: result, - ); + throw ArtifactBuildException.fromProcessResult(''' +Failed to build APK. +Command: $executable ${arguments.join(' ')} +Reason: Exited with code $exitCode.''', buildProcessResult: result); } }); final projectRoot = shorebirdEnv.getShorebirdProjectRoot()!; @@ -257,10 +260,10 @@ class ArtifactBuilder { final result = await process.run(executable, arguments); if (result.exitCode != ExitCode.success.code) { - throw ArtifactBuildException.fromProcessResult( - 'Failed to build', - buildProcessResult: result, - ); + throw ArtifactBuildException.fromProcessResult(''' +Failed to build AAR. +Command: $executable ${arguments.join(' ')} +Reason: Exited with code $exitCode.''', buildProcessResult: result); } }); } @@ -306,7 +309,10 @@ class ArtifactBuilder { final exitCode = await buildProcess.exitCode; if (exitCode != ExitCode.success.code) { throw ArtifactBuildException( - 'Failed to build', + ''' +Failed to build linux app. +Command: $executable ${arguments.join(' ')} +Reason: Exited with code $exitCode.''', stdout: stdoutLines, stderr: stderrLines, ); @@ -378,7 +384,10 @@ class ArtifactBuilder { final exitCode = await buildProcess.exitCode; if (exitCode != ExitCode.success.code) { throw ArtifactBuildException( - 'Failed to build', + ''' +Failed to build macOS app. +Command: $executable ${arguments.join(' ')} +Reason: Exited with code $exitCode.''', stdout: stdoutLines, stderr: stderrLines, ); @@ -458,7 +467,10 @@ class ArtifactBuilder { if (exitCode != ExitCode.success.code) { throw ArtifactBuildException( - 'Failed to build', + ''' +Failed to build IPA. +Command: $executable ${arguments.join(' ')} +Reason: Exited with code $exitCode.''', stdout: stdoutLines, stderr: stderrLines, ); @@ -469,7 +481,10 @@ class ArtifactBuilder { // https://github.com/shorebirdtech/shorebird/issues/2855 if (stderr.contains('Encountered error while creating the IPA')) { throw ArtifactBuildException( - 'Failed to build', + ''' +Failed to build IPA. +Command: $executable ${arguments.join(' ')} +Reason: stderr contains "Encountered error while creating the IPA".''', stdout: stdoutLines, stderr: stderrLines, ); @@ -507,7 +522,11 @@ class ArtifactBuilder { final result = await process.run(executable, arguments); if (result.exitCode != ExitCode.success.code) { - throw ArtifactBuildException('Failed to build: ${result.stderr}'); + throw ArtifactBuildException(''' +Failed to build iOS framework. +Command: $executable ${arguments.join(' ')} +Reason: Exited with code $exitCode. +'''); } appDillPath = findAppDill(stdout: result.stdout.toString()); diff --git a/packages/shorebird_cli/test/src/artifact_builder/artifact_builder_test.dart b/packages/shorebird_cli/test/src/artifact_builder/artifact_builder_test.dart index 03d82775..e740abb5 100644 --- a/packages/shorebird_cli/test/src/artifact_builder/artifact_builder_test.dart +++ b/packages/shorebird_cli/test/src/artifact_builder/artifact_builder_test.dart @@ -700,7 +700,10 @@ Either run `flutter pub get` manually, or follow the steps in ${cannotRunInVSCod isA().having( (e) => e.message, 'message', - equals('Failed to build'), + equals(''' +Failed to build linux app. +Command: flutter build linux --release +Reason: Exited with code 70.'''), ), ), ); @@ -1129,7 +1132,10 @@ error: exportArchive: No signing certificate "iOS Distribution" found''', () => runWithOverrides(() => builder.buildIpa(codesign: false)), throwsA( isA() - .having((e) => e.message, 'message', 'Failed to build') + .having((e) => e.message, 'message', ''' +Failed to build IPA. +Command: flutter build ipa --release --no-codesign +Reason: stderr contains "Encountered error while creating the IPA".''') .having( (e) => e.stderr, 'stderr', @@ -1185,7 +1191,10 @@ error: exportArchive No signing certificate "iOS Distribution" found''', () => runWithOverrides(() => builder.buildIpa(codesign: false)), throwsA( isA() - .having((e) => e.message, 'message', 'Failed to build') + .having((e) => e.message, 'message', ''' +Failed to build IPA. +Command: flutter build ipa --release --no-codesign +Reason: stderr contains "Encountered error while creating the IPA".''') .having( (e) => e.stderr, 'stderr',