Skip to content

Commit

Permalink
fix: Concat notarytool error with notarytool log result
Browse files Browse the repository at this point in the history
  • Loading branch information
Connor G Meehan committed May 8, 2024
1 parent a7698ef commit 514cb3d
Showing 1 changed file with 28 additions and 11 deletions.
39 changes: 28 additions & 11 deletions src/notarytool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
isNotaryToolApiKeyCredentials,
} from './validate-args';
import { NotaryToolCredentials, NotaryToolStartOptions } from './types';
import { parse } from 'path';

const d = debug('electron-notarize:notarytool');

Expand Down Expand Up @@ -83,29 +84,45 @@ export async function notarizeAndWaitForNotaryTool(opts: NotaryToolStartOptions)
];

const result = await spawn('xcrun', notarizeArgs);
let parsed: any;
try {
parsed = JSON.parse(result.output.trim());
} catch (err) {
throw new Error(`Failed to notarize via notarytool\n\nCould not parse output as JSON\n\n${result.output.trim()}`);
}

if (!parsed.status || parsed.status !== 'Accepted') {
if (result.code !== 0) {
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;
}

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');
});
}

0 comments on commit 514cb3d

Please sign in to comment.