8000 chore: wrapping Error in `exec` rejection so as to pass through error code to downstream logic by mmaietta · Pull Request #9138 · electron-userland/electron-builder · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

chore: wrapping Error in exec rejection so as to pass through error code to downstream logic #9138

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jun 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/little-pandas-mix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"builder-util": patch
---

chore: wrapping Error in exec rejection so as to pass through error code to downstream logic
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ jobs:
run: pnpm generate-all

test-windows:
runs-on: windows-2019
runs-on: windows-2022
timeout-minutes: 20
strategy:
fail-fast: false
Expand Down
9 changes: 6 additions & 3 deletions packages/builder-util/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export function exec(file: string, args?: Array<string> | null, options?: ExecFi
} else {
const code = (error as any).code
// https://github.com/npm/npm/issues/17624
if ((file.toLowerCase().endsWith("npm") || file.toLowerCase().endsWith("npm.cmd")) && args?.includes("list") && args?.includes("--silent")) {
if (code === 1 && (file.toLowerCase().endsWith("npm") || file.toLowerCase().endsWith("npm.cmd")) && args?.includes("list") && args?.includes("--silent")) {
console.error({ file, code }, error.message)
resolve(stdout.toString())
return
Expand All @@ -142,7 +142,8 @@ export function exec(file: string, args?: Array<string> | null, options?: ExecFi
message += `\n${chalk.red(stderr.toString())}`
}

reject(new Error(message))
// TODO: switch to ECMA Script 2026 Error class with `cause` property to return stack trace
reject(new ExecError(file, code, message, "", `${error.code || ExecError.code}`))
}
}
)
Expand Down Expand Up @@ -271,12 +272,14 @@ function formatOut(text: string, title: string) {
export class ExecError extends Error {
alreadyLogged = false

static code = "ERR_ELECTRON_BUILDER_CANNOT_EXECUTE"

constructor(
command: string,
readonly exitCode: number,
out: string,
errorOut: string,
code = "ERR_ELECTRON_BUILDER_CANNOT_EXECUTE"
code = ExecError.code
) {
super(`${command} process failed ${code}${formatOut(String(exitCode), "Exit code")}${formatOut(out, "Output")}${formatOut(errorOut, "Error output")}`)
;(this as NodeJS.ErrnoException).code = code
Expand Down
19 changes: 13 additions & 6 deletions packages/dmg-builder/src/dmg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import { TmpDir } from "temp-file"
import { addLicenseToDmg } from "./dmgLicense"
import { attachAndExecute, computeBackground, detach, getDmgVendorPath } from "./dmgUtil"
import { hdiUtil } from "./hdiuil"
import { hdiUtil, hdiutilTransientExitCodes } from "./hdiuil"

export class DmgTarget extends Target {
readonly options: DmgOptions = this.packager.config.dmg || Object.create(null)
Expand Down Expand Up @@ -197,20 +197,27 @@
}

async function createStageDmg(tempDmg: string, appPath: string, volumeName: string) {
//noinspection SpellCheckingInspection
const imageArgs = addLogLevel(["create", "-srcfolder", appPath, "-volname", volumeName, "-anyowners", "-nospotlight", "-format", "UDRW"])
const createArgs = ["create", "-srcfolder", appPath, "-volname", volumeName, "-anyowners", "-nospotlight", "-format", "UDRW"]
const imageArgs = addLogLevel(createArgs)
if (log.isDebugEnabled) {
imageArgs.push("-debug")
}

imageArgs.push("-fs", "APFS")
imageArgs.push(tempDmg)
await hdiUtil(imageArgs)
await hdiUtil(imageArgs).catch(async e => {
if (hdiutilTransientExitCodes.has(e.code)) {
// Delay then create, then retry with verbose output
await new Promise(resolve => setTimeout(resolve, 3000))
return hdiUtil(addLogLevel(createArgs, true))
}
throw e
})
return tempDmg
}

function addLogLevel(args: Array<string>): Array<string> {
args.push(process.env.DEBUG_DMG === "true" ? "-verbose" : "-quiet")
function addLogLevel(args: Array<string>, isVerbose = process.env.DEBUG_DMG === "true"): Array<string> {
args.push(isVerbose ? "-verbose" : "-quiet")
return args
}

Expand Down
2 changes: 1 addition & 1 deletion packages/dmg-builder/src/dmgUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
if (hdiutilTransientExitCodes.has(e.code)) {
// Delay then force unmount with verbose output
await new Promise(resolve => setTimeout(resolve, 3000))
return hdiUtil(["detach", "--force", name])
return hdiUtil(["detach", "-force", name])
}
throw e
})
Expand Down
4 changes: 2 additions & 2 deletions test/src/helpers/updaterTestUtil.ts
6D4E
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { NodeHttpExecutor, serializeToYaml, TmpDir } from "builder-util"
import { AllPublishOptions, DownloadOptions } from "builder-util-runtime"
import { AppUpdater, MacUpdater, NsisUpdater } from "electron-updater"
import { TestOnlyUpdaterOptions } from "electron-updater/out/AppUpdater"
import { NoOpLogger, TestOnlyUpdaterOptions } from "electron-updater/out/AppUpdater"
import { outputFile, writeFile } from "fs-extra"
import * as path from "path"
import { assertThat } from "./fileAssert"
Expand Down Expand Up @@ -75,7 +75,7 @@ export function tuneTestUpdater(updater: AppUpdater, options?: TestOnlyUpdaterOp
platform: "win32",
...options,
}
updater.logger = console
updater.logger = new NoOpLogger()
}

export function trackEvents(updater: AppUpdater) {
Expand Down
1 change: 0 additions & 1 deletion test/src/updater/differentialUpdateTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@ async function testBlockMap(expect: ExpectStatic, oldDir: string, newDir: string
platform: platform.nodeName as any,
isUseDifferentialDownload: true,
})
updater.logger = console

const currentUpdaterCacheDirName = (await updater.configOnDisk.value).updaterCacheDirName
if (currentUpdaterCacheDirName == null) {
Expand Down
0