Provide better information in error reports by printing the stack trace and message of the original error instead of the Err wrapper

This commit is contained in:
Martin Kleinschrodt 2022-07-29 16:36:32 +02:00
parent 7afd5582eb
commit 01dd5eaf2a
8 changed files with 23 additions and 28 deletions

View File

@ -1,7 +0,0 @@
<p>The following error occurred at {{ time }}:</p>
<p>
Code: {{ code }} <br />
Message: {{ message }} <br />
Event ID: {{ eventId }}`
</p>

View File

@ -1,5 +0,0 @@
The following error occurred at {{ time }}:
Code: {{ code }}
Message: {{ message }}
Event ID: {{ eventId }}`

5
assets/email/plain.html Normal file
View File

@ -0,0 +1,5 @@
<p>
<pre>
{{ message }}
</pre>
</p>

1
assets/email/plain.txt Normal file
View File

@ -0,0 +1 @@
{{ message }}

View File

@ -99,8 +99,10 @@ export class Err extends Error {
} }
toString() { toString() {
return `Time: ${this.time.toISOString()}\nError Code: ${this.code}:\nError Message: ${ return `Time: ${this.time.toISOString()}
this.message Error Code: ${this.code}
}\nStack Trace:\n${this.originalError ? this.originalError.stack : this.stack}`; Error Message: ${this.message}${this.originalError ? `\nOriginal Error Message: ${this.originalError.message}` : ""}
Stack Trace:\n${this.originalError ? this.originalError.stack : this.stack}
`;
} }
} }

View File

@ -60,8 +60,8 @@ export class JoinOrgInviteCompletedMessage extends Message<{ orgName: string; op
} }
} }
export class ErrorMessage extends Message<{ code: string; message: string; time: string; eventId: string }> { export class PlainMessage extends Message<{ message: string }> {
template = "error"; template = "plain";
get title() { get title() {
return "Padloc Error Notification"; return "Padloc Error Notification";

View File

@ -44,7 +44,7 @@ import { Org, OrgID, OrgMember, OrgMemberStatus, OrgRole, ScimSettings } from ".
import { Invite } from "./invite"; import { Invite } from "./invite";
import { import {
ConfirmMembershipInviteMessage, ConfirmMembershipInviteMessage,
ErrorMessage, PlainMessage,
JoinOrgInviteAcceptedMessage, JoinOrgInviteAcceptedMessage,
JoinOrgInviteCompletedMessage, JoinOrgInviteCompletedMessage,
JoinOrgInviteMessage, JoinOrgInviteMessage,
@ -2078,8 +2078,6 @@ export class Server {
} }
private async _handleError(error: Error, req: Request, res: Response, context: Context) { private async _handleError(error: Error, req: Request, res: Response, context: Context) {
console.error(error);
const e = const e =
error instanceof Err error instanceof Err
? error ? error
@ -2096,6 +2094,8 @@ export class Server {
}; };
if (e.report) { if (e.report) {
console.error(error);
const evt = this.log("error", context, { const evt = this.log("error", context, {
error: e.toRaw(), error: e.toRaw(),
request: { request: {
@ -2108,13 +2108,12 @@ export class Server {
try { try {
await this.messenger.send( await this.messenger.send(
this.config.reportErrors, this.config.reportErrors,
new ErrorMessage({ new PlainMessage({
time: e.time.toISOString(), message: `The following error occured at ${e.time.toISOString()}:\n\nEndpoint: ${
code: e.code, req.method
message: `Endpoint: ${req.method}\nMessage: ${e.message}\nDevice Info:\n${ }\nDevice Info:\n${
req.device && JSON.stringify(req.device?.toRaw(), null, 4) req.device && JSON.stringify(req.device?.toRaw(), null, 4)
}\nStack Trace:\n${e.stack}`, }\n${e.toString()}${evt?.id ? `Event ID: ${evt.id}` : ""}`,
eventId: evt.id,
}) })
); );
} catch (e) {} } catch (e) {}

View File

@ -11,7 +11,7 @@ import { AuthServer, AuthType } from "@padloc/core/src/auth";
import { WebAuthnConfig, WebAuthnServer } from "./auth/webauthn"; import { WebAuthnConfig, WebAuthnServer } from "./auth/webauthn";
import { SMTPSender } from "./email/smtp"; import { SMTPSender } from "./email/smtp";
import { MongoDBStorage } from "./storage/mongodb"; import { MongoDBStorage } from "./storage/mongodb";
import { ConsoleMessenger, ErrorMessage } from "@padloc/core/src/messenger"; import { ConsoleMessenger, PlainMessage } from "@padloc/core/src/messenger";
import { FSAttachmentStorage, FSAttachmentStorageConfig } from "./attachments/fs"; import { FSAttachmentStorage, FSAttachmentStorageConfig } from "./attachments/fs";
import { import {
AttachmentStorageConfig, AttachmentStorageConfig,
@ -302,7 +302,7 @@ async function init(config: PadlocConfig) {
try { try {
await emailSender.send( await emailSender.send(
config.server.reportErrors, config.server.reportErrors,
new ErrorMessage({ new PlainMessage({
code: ErrorCode.UNKNOWN_ERROR, code: ErrorCode.UNKNOWN_ERROR,
message: `${err.message}\n${err.stack}`, message: `${err.message}\n${err.stack}`,
time: new Date().toISOString(), time: new Date().toISOString(),