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

[EuiErrorBoundary] Show message in non-Chromium browsers #4324

Merged
merged 3 commits into from
Dec 1, 2020
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
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
## [`master`](https://github.com/elastic/eui/tree/master)

No public interface changes since `30.5.1`.
**Bug fixes**

- Expose `EuiErrorBoundary` error message not showing in non-Chromium browsers ([#4324](https://github.com/elastic/eui/pull/4324))

## [`30.5.1`](https://github.com/elastic/eui/tree/v30.5.1)

Expand Down
12 changes: 9 additions & 3 deletions src/components/error_boundary/error_boundary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { EuiText } from '../text';

interface EuiErrorBoundaryState {
hasError: boolean;
error?: Error;
error?: string;
}

export type EuiErrorBoundaryProps = CommonProps &
Expand Down Expand Up @@ -55,8 +55,14 @@ export class EuiErrorBoundary extends Component<
this.state = errorState;
}

componentDidCatch(error: Error) {
componentDidCatch({ message, stack }: Error) {
// Display fallback UI
// Only Chrome includes the `message` property as part of `stack`.
// For consistency, rebuild the full error text from the Error subparts.
const idx = stack?.indexOf(message) || -1;
const stackStr = idx > -1 ? stack?.substr(idx + message.length + 1) : stack;
const error = `Error: ${message}
${stackStr}`;
this.setState({
hasError: true,
error,
Expand All @@ -74,7 +80,7 @@ export class EuiErrorBoundary extends Component<
<EuiText size="xs">
<h1>Error</h1>
<pre className="euiErrorBoundary__stack">
<p>{this.state.error && this.state.error.stack}</p>
<p>{this.state.error}</p>
</pre>
thompsongl marked this conversation as resolved.
Show resolved Hide resolved
</EuiText>
</div>
Expand Down