From 5126d1fadaa49c22cee3f6194edb340a15e0fa89 Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Thu, 21 Feb 2019 14:59:11 -0500 Subject: [PATCH] Fix #1493: Don't crash when the reps error out (#1513) * Fix #1493: Don't crash when the reps error out * Put handler in ValueRenderer. Provide information about error. * Also display `toString` --- src/components/reps/value-renderer.jsx | 27 ++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/components/reps/value-renderer.jsx b/src/components/reps/value-renderer.jsx index e4e7a927dd..4532b8654a 100644 --- a/src/components/reps/value-renderer.jsx +++ b/src/components/reps/value-renderer.jsx @@ -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 ( +
+
{value.toString()}
+

A value renderer encountered an error.

+
+            {this.state.error && this.state.error.toString()}
+            
+ {this.state.errorInfo.componentStack} +
+ + Please file a bug report. + +
+ ); + } + const htmlString = UserReps.getUserRepIfAvailable(value); if (htmlString) { return ;