Skip to content

Commit

Permalink
Fix #1493: Don't crash when the reps error out (#1513)
Browse files Browse the repository at this point in the history
* Fix #1493: Don't crash when the reps error out

* Put handler in ValueRenderer.  Provide information about error.

* Also display `toString`
  • Loading branch information
mdboom authored and bcolloran committed Feb 21, 2019
1 parent b18b0b7 commit 5126d1f
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/components/reps/value-renderer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,35 @@ export default class ValueRenderer extends React.Component {
valueToRender: PropTypes.any
};

constructor(props) {
super(props);
this.state = {};
}

componentDidCatch(error, errorInfo) {
this.setState({ error, errorInfo });
}

render() {
const value = this.props.valueToRender;

if (this.state.errorInfo) {
return (
<div>
<pre>{value.toString()}</pre>
<h2>A value renderer encountered an error.</h2>
<pre>
{this.state.error && this.state.error.toString()}
<br />
{this.state.errorInfo.componentStack}
</pre>
<a href="https://github.com/iodide-project/iodide/issues/new">
Please file a bug report.
</a>
</div>
);
}

const htmlString = UserReps.getUserRepIfAvailable(value);
if (htmlString) {
return <HTMLHandler htmlString={htmlString} />;
Expand Down

0 comments on commit 5126d1f

Please sign in to comment.