Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Reporting] Refactor error messages with human-friendly version of message #136501

Merged
merged 3 commits into from
Jul 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 18 additions & 28 deletions x-pack/plugins/reporting/common/errors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
/* eslint-disable max-classes-per-file */
import { i18n } from '@kbn/i18n';

export interface ReportingError {
/**
* Return a message describing the error that is human friendly
*/
humanFriendlyMessage?(): string;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am just curious why you decided not to go with the built-in toString() method? That seems like it can very well fit into our use case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question!

In most cases on the server-side we will be using the default toString behaviour. But when storing this as a message on the Reporting document (where it is seen by users) sometimes we want to have a special human-friendlier version of the stringified error. Does that make sense? Is there another way to achieve this? Perhaps toString('humanFriendly')?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @jloleysens. That makes total sense now 👍

No need to overcomplicate this. The current solution is clear enough.

}
export abstract class ReportingError extends Error {
/**
* A string that uniquely brands an error type. This is used to power telemetry
Expand Down Expand Up @@ -87,17 +93,10 @@ export class PdfWorkerOutOfMemoryError extends ReportingError {
return PdfWorkerOutOfMemoryError.code;
}

details = i18n.translate('xpack.reporting.common.pdfWorkerOutOfMemoryErrorMessage', {
defaultMessage:
'Cannot generate PDF due to low memory. Consider making a smaller PDF before retrying this report.',
});

/**
* No need to provide extra details, we know exactly what happened and can provide
* a nicely formatted message
*/
public override get message(): string {
return this.details;
public humanFriendlyMessage() {
return i18n.translate('xpack.reporting.common.pdfWorkerOutOfMemoryErrorMessage', {
defaultMessage: `Can't generate a PDF due to insufficient memory. Try making a smaller PDF and retrying this report.`,
});
}
}

Expand All @@ -107,16 +106,10 @@ export class BrowserCouldNotLaunchError extends ReportingError {
return BrowserCouldNotLaunchError.code;
}

details = i18n.translate('xpack.reporting.common.browserCouldNotLaunchErrorMessage', {
defaultMessage: 'Cannot generate screenshots because the browser did not launch.',
});

/**
* For this error message we expect that users will use the diagnostics
* functionality in reporting to debug further.
*/
public override get message() {
return this.details;
public humanFriendlyMessage() {
return i18n.translate('xpack.reporting.common.browserCouldNotLaunchErrorMessage', {
defaultMessage: `Can't generate screenshots because the browser did not launch. See the server logs for more information.`,
});
}
}

Expand Down Expand Up @@ -151,12 +144,9 @@ export class VisualReportingSoftDisabledError extends ReportingError {
return VisualReportingSoftDisabledError.code;
}

details = i18n.translate('xpack.reporting.common.cloud.insufficientSystemMemoryError', {
defaultMessage:
'This report cannot be generated because Kibana does not have sufficient memory.',
});

public override get message() {
return this.details;
humanFriendlyMessage() {
return i18n.translate('xpack.reporting.common.cloud.insufficientSystemMemoryError', {
defaultMessage: `Can't generate this report due to insufficient memory.`,
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ export class ExecuteReportTask implements ReportingTask {
docOutput.error_code = output.error_code;
} else {
const defaultOutput = null;
docOutput.content = output.toString() || defaultOutput;
docOutput.content = output.humanFriendlyMessage?.() || output.toString() || defaultOutput;
docOutput.content_type = unknownMime;
docOutput.warnings = [output.toString()];
docOutput.error_code = output.code;
Expand Down