Skip to content

Commit

Permalink
[Reporting] Refactor error messages with human-friendly version of me…
Browse files Browse the repository at this point in the history
…ssage (#136501)

* refactor error code messages with new method specifically for human-friendly version of errors

* update error copy

Co-authored-by: Kibana Machine <[email protected]>
  • Loading branch information
jloleysens and kibanamachine authored Jul 22, 2022
1 parent d16a4d8 commit af3a3cb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 29 deletions.
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;
}
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

0 comments on commit af3a3cb

Please sign in to comment.