File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -4,6 +4,8 @@ import * as http from 'http';
44import { EventEmitter } from 'events' ;
55import type { MessagePortMain } from 'electron' ;
66
7+ import { logError } from './errors.ts' ;
8+
79export interface HtkOperation {
810 name : string ;
911 description : string ;
@@ -112,12 +114,22 @@ export class UiBridge extends EventEmitter {
112114
113115 this . pending . set ( id , { resolve, reject, timer } ) ;
114116
115- this . port ! . postMessage ( {
116- type : 'request' ,
117- id,
118- operation,
119- params
120- } ) ;
117+ try {
118+ this . port ! . postMessage ( {
119+ type : 'request' ,
120+ id,
121+ operation,
122+ params
123+ } ) ;
124+ } catch ( err : any ) {
125+ clearTimeout ( timer ) ;
126+ this . pending . delete ( id ) ;
127+ const error = new Error (
128+ `Failed to send '${ operation } ' request to renderer: ${ err . message } `
129+ ) ;
130+ logError ( error ) ;
131+ reject ( error ) ;
132+ }
121133 } ) ;
122134 }
123135
@@ -142,6 +154,7 @@ export class UiBridge extends EventEmitter {
142154 res . end ( JSON . stringify ( { error : 'not_found' } ) ) ;
143155 }
144156 } catch ( err : any ) {
157+ logError ( err ) ;
145158 res . writeHead ( 500 ) ;
146159 res . end ( JSON . stringify ( { error : 'internal_error' , message : err . message } ) ) ;
147160 }
@@ -209,6 +222,7 @@ export class UiBridge extends EventEmitter {
209222 res . writeHead ( 200 ) ;
210223 res . end ( JSON . stringify ( result ) ) ;
211224 } catch ( err : any ) {
225+ logError ( new Error ( `Operation '${ parsed . name } ' failed: ${ err . message } ` ) ) ;
212226 res . writeHead ( 502 ) ;
213227 res . end ( JSON . stringify ( { error : 'execution_failed' , message : err . message } ) ) ;
214228 }
You can’t perform that action at this time.
0 commit comments