Skip to content

fix(package): ensure electron-packager throws if fails - #3136

Merged
erickzhao merged 1 commit into
mainfrom
fix/ensure-electron-packager-fail
Jan 11, 2023
Merged

erickzhao merged 1 commit into
mainfrom
fix/ensure-electron-packager-fail

Conversation

@erickzhao

@erickzhao erickzhao commented Jan 11, 2023 •

Copy link
Copy Markdown
Member
  • I have read the contribution documentation for this project.
  • I agree to follow the code of conduct that this project follows, as appropriate.
  • The changes are appropriately documented (if applicable).
  • The changes have sufficient test coverage (if applicable).
  • The testsuite passes successfully on my local machine (if applicable).

Summarize your changes:

Fixes #3128

For context, we use some pretty ugly hacks for Electron Packager to work with Listr2 (without being written with Listr2 itself).

To make this work, there's a single packagerPromise resolving from the electron-packager call:

ctx.packagerPromise = packager(packageOpts);
// Handle error by failing this task
// rejects is populated by the reject handlers for every
// signal based promise in every subtask
ctx.packagerPromise.catch((err) => {
for (const reject of rejects) reject(err);
});

If this Promise rejects, then we catch it and reject it with an array of reject handlers from all subtasks declared above:

const rejects: ((err: any) => void)[] = [];

The problem here is that the rejects array is empty in the first .catch(), so the error is caught but never propagated. Therefore, the CLI ends up stalling indefinitely.

To solve this problem, we add the Promise reject handler from targetsPromise to the rejects array so the packagerPromise catch clause has a valid rejects target.

const targetsPromise = new Promise<InternalTargetDefinition[]>((resolve, reject) => {
  provideTargets = resolve;
  rejects.push(reject);
});

@erickzhao
erickzhao force-pushed the fix/ensure-electron-packager-fail branch from 4ecc744 to a6bce41 Compare January 11, 2023 01:10
@erickzhao
erickzhao merged commit 4c813a7 into main Jan 11, 2023
@erickzhao
erickzhao deleted the fix/ensure-electron-packager-fail branch January 11, 2023 18:29
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.

yarn package stalls if missing mandatory fields

2 participants