From 195de70e57474e8bf0a2955a61e8a0a1103cdece Mon Sep 17 00:00:00 2001 From: Connor G Meehan Date: Thu, 9 May 2024 09:26:34 +1000 Subject: [PATCH] refact: Simplified notary error handling logic --- src/notarytool.ts | 64 ++++++++++++++++++++++------------------------- 1 file changed, 30 insertions(+), 34 deletions(-) diff --git a/src/notarytool.ts b/src/notarytool.ts index e1b7ef3..d2067dc 100644 --- a/src/notarytool.ts +++ b/src/notarytool.ts @@ -84,44 +84,40 @@ export async function notarizeAndWaitForNotaryTool(opts: NotaryToolStartOptions) const result = await spawn('xcrun', notarizeArgs); - if (result.code !== 0) { - let parsed: any; - try { - parsed = JSON.parse(result.output.trim()); - } catch (err) { - throw new Error( - `Failed to notarize via notarytool. Failed with unexpected result: \n\n${result.output.trim()}`, - ); - } - - let logId: undefined | string; - if (!parsed.status || parsed.status !== 'Accepted') { - logId = parsed.id; - } + if (result.code === 0) { + d('notarization success'); + return; + } - let logOutput: undefined | string; - if (logId) { - try { - 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); - } - } + let parsed: any; + try { + parsed = JSON.parse(result.output.trim()); + } catch (err) { + throw new Error( + `Failed to notarize via notarytool. Failed with unexpected result: \n\n${result.output.trim()}`, + ); + } - let message = `Failed to notarize via notarytool\n\n${result.output}`; - if (logOutput) { - message += `\n\nDiagnostics from notarytool log: ${logOutput}`; + let logOutput: undefined | string; + if (parsed.id) { + try { + 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(message); } - 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); }); }