@@ -161,6 +161,30 @@ export class DockerDesktopInstallation {
161
161
} ) ;
162
162
} ) ;
163
163
}
164
+ // encode the error to be sent over IPC
165
+ // this is needed because on the client it will display
166
+ // a generic error message 'Error invoking remote method' and
167
+ // it's not useful for end user
168
+ encodeIpcError ( e : unknown ) : { name ?: string ; message : unknown ; extra ?: Record < string , unknown > } {
169
+ let builtError ;
170
+ if ( e instanceof Error ) {
171
+ builtError = { name : e . name , message : e . message , extra : { ...e } } ;
172
+ } else {
173
+ builtError = { message : e } ;
174
+ }
175
+ return builtError ;
176
+ }
177
+
178
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
179
+ ipcHandle ( channel : string , listener : ( event : IpcMainInvokeEvent , ...args : any [ ] ) => Promise < void > | any ) : any {
180
+ ipcMain . handle ( channel , async ( ...args ) => {
181
+ try {
182
+ return { result : await Promise . resolve ( listener ( ...args ) ) } ;
183
+ } catch ( e ) {
184
+ return { error : this . encodeIpcError ( e ) } ;
185
+ }
186
+ } ) ;
187
+ }
164
188
165
189
async init ( ) : Promise < void > {
166
190
ipcMain . handle ( 'docker-desktop-plugin:get-preload-script' , async ( ) : Promise < string > => {
@@ -177,10 +201,10 @@ export class DockerDesktopInstallation {
177
201
} ,
178
202
) ;
179
203
180
- ipcMain . handle (
204
+ this . ipcHandle (
181
205
'docker-desktop-plugin:delete' ,
182
- async ( event : IpcMainInvokeEvent , extensionName : string ) : Promise < void > => {
183
- return this . contributionManager . deleteExtension ( extensionName ) ;
206
+ async ( event : IpcMainInvokeEvent , extensionId : string ) : Promise < void > => {
207
+ return this . contributionManager . deleteExtension ( extensionId ) ;
184
208
} ,
185
209
) ;
186
210
0 commit comments