@@ -83,24 +83,42 @@ export async function notarizeAndWaitForNotaryTool(opts: NotaryToolStartOptions)
83
83
] ;
84
84
85
85
const result = await spawn ( 'xcrun' , notarizeArgs ) ;
86
- const parsed = JSON . parse ( result . output . trim ( ) ) ;
86
+ const rawOut = result . output . trim ( ) ;
87
87
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 ) {
89
104
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 ;
99
113
} catch ( e ) {
100
114
d ( 'failed to pull notarization logs' , e ) ;
101
115
}
102
- throw new Error ( `Failed to notarize via notarytool\n\n${ result . output } ` ) ;
103
116
}
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 ) ;
105
123
} ) ;
106
124
}
0 commit comments