Skip to content
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

fix: Brittle response parsing from notarytool #191

Merged
merged 8 commits into from
May 14, 2024
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: 2.1

orbs:
cfa: continuousauth/[email protected]
node: electronjs/[email protected].1
node: electronjs/[email protected].2

workflows:
test_and_release:
Expand Down
44 changes: 31 additions & 13 deletions src/notarytool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}