diff --git a/.circleci/config.yml b/.circleci/config.yml index 8cce559..3020638 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -2,7 +2,7 @@ version: 2.1 orbs: cfa: continuousauth/npm@2.1.0 - node: electronjs/node@2.2.1 + node: electronjs/node@2.2.2 workflows: test_and_release: diff --git a/src/notarytool.ts b/src/notarytool.ts index 6b43431..51ef7d7 100644 --- a/src/notarytool.ts +++ b/src/notarytool.ts @@ -83,24 +83,42 @@ export async function notarizeAndWaitForNotaryTool(opts: NotaryToolStartOptions) ]; const result = await spawn('xcrun', notarizeArgs); - const parsed = JSON.parse(result.output.trim()); + const rawOut = result.output.trim(); - if (result.code !== 0 || !parsed.status || parsed.status !== 'Accepted') { + let parsed: any; + try { + parsed = JSON.parse(rawOut); + } catch (err) { + throw new Error( + `Failed to notarize via notarytool. Failed with unexpected result: \n\n${rawOut}`, + ); + } + + if (result.code === 0 && parsed.status === 'Accepted') { + d('notarization success'); + return; + } + + let logOutput: undefined | string; + if (parsed.id) { try { - if (parsed && parsed.id) { - const logResult = await spawn('xcrun', [ - 'notarytool', - 'log', - parsed.id, - ...authorizationArgs(opts), - ]); - d('notarization log', logResult.output); - } + const logResult = await spawn('xcrun', [ + 'notarytool', + 'log', + parsed.id, + ...authorizationArgs(opts), + ]); + d('notarization log', logResult.output); + logOutput = logResult.output; } catch (e) { d('failed to pull notarization logs', e); } - throw new Error(`Failed to notarize via notarytool\n\n${result.output}`); } - d('notarization success'); + + let message = `Failed to notarize via notarytool\n\n${result.output}`; + if (logOutput) { + message += `\n\nDiagnostics from notarytool log: ${logOutput}`; + } + throw new Error(message); }); }