From cedcdc6bffe5db208823892528ac4b4be288866b Mon Sep 17 00:00:00 2001 From: Dmitry S Date: Mon, 11 Apr 2022 09:52:34 -0400 Subject: [PATCH] (core) Improve debug logging related for client-side errors and sandbox crashes. Summary: - Include docId when available for client-side error reporting - Distinguish sandbox crashes from forced exits Test Plan: Tested manually Reviewers: paulfitz Reviewed By: paulfitz Differential Revision: https://phab.getgrist.com/D3373 --- app/client/models/errors.ts | 2 ++ app/server/lib/FlexServer.ts | 1 + app/server/lib/NSandbox.ts | 7 ++++++- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/client/models/errors.ts b/app/client/models/errors.ts index a6e0b207..7def3c36 100644 --- a/app/client/models/errors.ts +++ b/app/client/models/errors.ts @@ -177,11 +177,13 @@ export function setUpErrorHandling(doReportError = reportError, koUtil?: any) { */ function _logError(error: Error|string) { if (!pageHasHome()) { return; } + const docId = G.window.gristDocPageModel?.currentDocId?.get(); fetchFromHome('/api/log', { method: 'POST', body: JSON.stringify({ // Errors don't stringify, so pick out properties explicitly for errors. event: (error instanceof Error) ? pick(error, Object.getOwnPropertyNames(error)) : error, + docId, page: G.window.location.href, browser: pick(G.window.navigator, ['language', 'platform', 'userAgent']) }), diff --git a/app/server/lib/FlexServer.ts b/app/server/lib/FlexServer.ts index fcc025ac..af7352a2 100644 --- a/app/server/lib/FlexServer.ts +++ b/app/server/lib/FlexServer.ts @@ -576,6 +576,7 @@ export class FlexServer implements GristServer { const mreq = req as RequestWithLogin; log.rawWarn('client error', { event: req.body.event, + docId: req.body.docId, page: req.body.page, browser: req.body.browser, org: mreq.org, diff --git a/app/server/lib/NSandbox.ts b/app/server/lib/NSandbox.ts index e6112089..bb6d35b6 100644 --- a/app/server/lib/NSandbox.ts +++ b/app/server/lib/NSandbox.ts @@ -233,8 +233,13 @@ export class NSandbox implements ISandbox { } private _onExit(code: number, signal: string) { + const expected = this._isWriteClosed; this._close(); - log.rawDebug(`Sandbox exited with code ${code} signal ${signal}`, this._logMeta); + if (expected) { + log.rawDebug(`Sandbox exited with code ${code} signal ${signal}`, this._logMeta); + } else { + log.rawWarn(`Sandbox unexpectedly exited with code ${code} signal ${signal}`, this._logMeta); + } }