Skip to content

Commit 8440fa1

Browse files
connorgmeehanConnor G Meehanelectron-roller[bot]MarshallOfSound
authored
fix: Brittle response parsing from notarytool (#191)
* fix: Brittle response parsing from notarytool * fix: Fixes result.code check blocking notarytool log diagnostics * fix: Concat notarytool error with notarytool log result * clean: Cleanup unused import * refact: Simplified notary error handling logic * chore: bump electronjs/node in .circleci/config.yml to 2.2.2 (#195) Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> * fix: ensure status is Accepted --------- Co-authored-by: Connor G Meehan <[email protected]> Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: Samuel Attard <[email protected]>
1 parent f48a181 commit 8440fa1

File tree

1 file changed

+31
-13
lines changed

1 file changed

+31
-13
lines changed

src/notarytool.ts

+31-13
Original file line numberDiff line numberDiff line change
@@ -83,24 +83,42 @@ export async function notarizeAndWaitForNotaryTool(opts: NotaryToolStartOptions)
8383
];
8484

8585
const result = await spawn('xcrun', notarizeArgs);
86-
const parsed = JSON.parse(result.output.trim());
86+
const rawOut = result.output.trim();
8787

88-
if (result.code !== 0 || !parsed.status || parsed.status !== 'Accepted') {
88+
let parsed: any;
89+
try {
90+
parsed = JSON.parse(rawOut);
91+
} catch (err) {
92+
throw new Error(
93+
`Failed to notarize via notarytool. Failed with unexpected result: \n\n${rawOut}`,
94+
);
95+
}
96+
97+
if (result.code === 0 && parsed.status === 'Accepted') {
98+
d('notarization success');
99+
return;
100+
}
101+
102+
let logOutput: undefined | string;
103+
if (parsed.id) {
89104
try {
90-
if (parsed && parsed.id) {
91-
const logResult = await spawn('xcrun', [
92-
'notarytool',
93-
'log',
94-
parsed.id,
95-
...authorizationArgs(opts),
96-
]);
97-
d('notarization log', logResult.output);
98-
}
105+
const logResult = await spawn('xcrun', [
106+
'notarytool',
107+
'log',
108+
parsed.id,
109+
...authorizationArgs(opts),
110+
]);
111+
d('notarization log', logResult.output);
112+
logOutput = logResult.output;
99113
} catch (e) {
100114
d('failed to pull notarization logs', e);
101115
}
102-
throw new Error(`Failed to notarize via notarytool\n\n${result.output}`);
103116
}
104-
d('notarization success');
117+
118+
let message = `Failed to notarize via notarytool\n\n${result.output}`;
119+
if (logOutput) {
120+
message += `\n\nDiagnostics from notarytool log: ${logOutput}`;
121+
}
122+
throw new Error(message);
105123
});
106124
}

0 commit comments

Comments
 (0)