fix: ensure non-zero exit code on packaging/publishing errors#345
Merged
Conversation
- Add top-level try-catch with exit(1) in fastforge and flutter_distributor bin/main.dart so CI always receives a non-zero exit code when an error propagates out of the tool - Fix publish() to use a catch-all handler instead of 'on Error catch', ensuring Exception subclasses (e.g. DioException, IOException) are also logged before being rethrown - Fix pkg maker: check exit codes for xcrun productbuild, pkgutil --expand and pkgutil --flatten, and throw MakeError with a descriptive message on failure instead of silently continuing Fixes #344 Co-authored-by: Copilot <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
修复 #344 — 打包/发布出错时,工具退出码为 0,导致 CI 系统无法检测到失败。
根本原因分析
1.
bin/main.dart缺少顶层错误处理(主要修复)fastforge和flutter_distributor的入口函数没有 try-catch,只是直接return await cli.run(args)。当异常传播到main()时,虽然 Dart 理论上会以非零退出码退出,但在某些调用方式下(如dart pub global run)行为不稳定。新增显式exit(1)确保 CI 始终收到非零退出码。2.
publish()方法仅捕获Error,不捕获Exceptionunified_distributor.dart中publish()使用on Error catch,导致DioException、IOException等Exception子类绕过日志记录(虽然异常仍会继续传播)。改为通用catch确保所有异常都被记录后再重新抛出。3.
pkgmaker 未检查子进程退出码app_package_maker_pkg.dart中以下命令未检查退出码,失败时静默继续执行:xcrun productbuildpkgutil --expandpkgutil --flatten现在在每个命令失败时抛出带有详细信息的
MakeError。变更文件
packages/fastforge/bin/main.dart— 顶层 try-catch + exit(1)packages/flutter_distributor/bin/main.dart— 同上packages/unified_distributor/lib/src/unified_distributor.dart— publish() 改为通用 catchpackages/flutter_app_packager/lib/src/makers/pkg/app_package_maker_pkg.dart— 检查 productbuild/pkgutil 退出码