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
33 changes: 27 additions & 6 deletions src/notarytool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,24 +83,45 @@ export async function notarizeAndWaitForNotaryTool(opts: NotaryToolStartOptions)
];

const result = await spawn('xcrun', notarizeArgs);
const parsed = JSON.parse(result.output.trim());

if (result.code !== 0 || !parsed.status || parsed.status !== 'Accepted') {
if (result.code !== 0) {
connorgmeehan marked this conversation as resolved.
Show resolved Hide resolved
let parsed: any;
try {
if (parsed && parsed.id) {
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;
connorgmeehan marked this conversation as resolved.
Show resolved Hide resolved
}

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);
}
} catch (e) {
d('failed to pull notarization logs', e);
}
throw new Error(`Failed to notarize via notarytool\n\n${result.output}`);

let message = `Failed to notarize via notarytool\n\n${result.output}`;
if (logOutput) {
message += `\n\nDiagnostics from notarytool log: ${logOutput}`;
}
throw new Error(message);
}

d('notarization success');
});
}