File tree Expand file tree Collapse file tree 1 file changed +17
-1
lines changed
background-charm-service/src Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -71,7 +71,7 @@ onConsole(
7171 }
7272 }
7373 ctx = ctx ?? "Charm(NO_CHARM)" ;
74- return [ ctx , ...args ] ;
74+ return [ ctx , ...fmtConsole ( args ) ] ;
7575 } ,
7676) ;
7777
@@ -190,6 +190,22 @@ async function runCharm(data: RunData): Promise<void> {
190190 }
191191}
192192
193+ // Logs here are often viewed through observability dashboards
194+ // that don't render objects well. Attempt to stringify any objects
195+ // here.
196+ function fmtConsole ( args : any [ ] ) : any [ ] {
197+ return [ ...args ] . map ( ( value ) => {
198+ if ( value && typeof value === "object" ) {
199+ try {
200+ return JSON . stringify ( value ) ;
201+ } catch ( _e ) {
202+ // satisfy typescript's empty block
203+ }
204+ }
205+ return value ;
206+ } ) ;
207+ }
208+
193209self . addEventListener ( "unhandledrejection" , ( e : PromiseRejectionEvent ) => {
194210 // Throw this so that `WorkerController`'s `error` handler can handle
195211 // unhandled rejections the same way unhandled errors are handled.
You can’t perform that action at this time.
0 commit comments