Skip to content

fix: ensure non-zero exit code on packaging/publishing errors#345

Merged
lijy91 merged 1 commit into
mainfrom
fix/issue-344-exit-code-on-error
Jun 22, 2026
Merged

fix: ensure non-zero exit code on packaging/publishing errors#345
lijy91 merged 1 commit into
mainfrom
fix/issue-344-exit-code-on-error

Conversation

@lijy91

@lijy91 lijy91 commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

问题

修复 #344 — 打包/发布出错时,工具退出码为 0,导致 CI 系统无法检测到失败。

根本原因分析

1. bin/main.dart 缺少顶层错误处理(主要修复)

fastforgeflutter_distributor 的入口函数没有 try-catch,只是直接 return await cli.run(args)。当异常传播到 main() 时,虽然 Dart 理论上会以非零退出码退出,但在某些调用方式下(如 dart pub global run)行为不稳定。新增显式 exit(1) 确保 CI 始终收到非零退出码。

2. publish() 方法仅捕获 Error,不捕获 Exception

unified_distributor.dartpublish() 使用 on Error catch,导致 DioExceptionIOExceptionException 子类绕过日志记录(虽然异常仍会继续传播)。改为通用 catch 确保所有异常都被记录后再重新抛出。

3. pkg maker 未检查子进程退出码

app_package_maker_pkg.dart 中以下命令未检查退出码,失败时静默继续执行:

  • xcrun productbuild
  • pkgutil --expand
  • pkgutil --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() 改为通用 catch
  • packages/flutter_app_packager/lib/src/makers/pkg/app_package_maker_pkg.dart — 检查 productbuild/pkgutil 退出码

- 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]>
@lijy91
lijy91 changed the base branch from dev to main June 22, 2026 04:05
@lijy91
lijy91 merged commit 82469a7 into main Jun 22, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant