From 048c8d8522fbc46930bc68d7cf508c1b7ed7db72 Mon Sep 17 00:00:00 2001 From: Sergey Tarasov Date: Wed, 17 Aug 2016 23:11:37 +0300 Subject: [PATCH 1/4] throws error on client --- node_package/src/handleError.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/node_package/src/handleError.js b/node_package/src/handleError.js index 0c5f70b70..a977e60cd 100644 --- a/node_package/src/handleError.js +++ b/node_package/src/handleError.js @@ -53,14 +53,19 @@ export default (options) => { console.error(`message: ${e.message}`); console.error(`stack: ${e.stack}`); - if (serverSide) { - msg += `Exception in rendering! + msg += `Exception in rendering! ${e.fileName ? `\nlocation: ${e.fileName}:${e.lineNumber}` : ''} Message: ${e.message} ${e.stack}`; + if (serverSide) { const reactElement = React.createElement('pre', null, msg); return ReactDOMServer.renderToString(reactElement); + } else { + var newError = new Error(msg); + + newError.cause = e; + throw newError; } }; From 84824b132a5fc755962218df846a620e6d6e128a Mon Sep 17 00:00:00 2001 From: Sergey Tarasov Date: Thu, 18 Aug 2016 15:15:44 +0300 Subject: [PATCH 2/4] moved throw from handleError to clientStartup --- node_package/src/clientStartup.js | 7 ++----- node_package/src/handleError.js | 9 ++------- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/node_package/src/clientStartup.js b/node_package/src/clientStartup.js index 0075bfb72..0c7ebba54 100644 --- a/node_package/src/clientStartup.js +++ b/node_package/src/clientStartup.js @@ -78,11 +78,8 @@ You should return a React.Component always for the client side entry point.`); } } } catch (e) { - handleError({ - e, - name, - serverSide: false, - }); + e.message = `Exception in rendering ${name}. ${e.message}`; + throw e; } } diff --git a/node_package/src/handleError.js b/node_package/src/handleError.js index a977e60cd..0c5f70b70 100644 --- a/node_package/src/handleError.js +++ b/node_package/src/handleError.js @@ -53,19 +53,14 @@ export default (options) => { console.error(`message: ${e.message}`); console.error(`stack: ${e.stack}`); - msg += `Exception in rendering! + if (serverSide) { + msg += `Exception in rendering! ${e.fileName ? `\nlocation: ${e.fileName}:${e.lineNumber}` : ''} Message: ${e.message} ${e.stack}`; - if (serverSide) { const reactElement = React.createElement('pre', null, msg); return ReactDOMServer.renderToString(reactElement); - } else { - var newError = new Error(msg); - - newError.cause = e; - throw newError; } }; From 7d7dddbffbe582fd77efce059df269bae6082286 Mon Sep 17 00:00:00 2001 From: Sergey Tarasov Date: Fri, 19 Aug 2016 12:41:52 +0300 Subject: [PATCH 3/4] modified message, updated js styling --- node_package/src/clientStartup.js | 3 ++- node_package/src/handleError.js | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/node_package/src/clientStartup.js b/node_package/src/clientStartup.js index 0c7ebba54..9a67ba8e9 100644 --- a/node_package/src/clientStartup.js +++ b/node_package/src/clientStartup.js @@ -78,7 +78,8 @@ You should return a React.Component always for the client side entry point.`); } } } catch (e) { - e.message = `Exception in rendering ${name}. ${e.message}`; + e.message = `ReactOnRails encountered an error while rendering component: ${name}.` + + `Original message: ${e.message}`; throw e; } } diff --git a/node_package/src/handleError.js b/node_package/src/handleError.js index 0c5f70b70..d0a465cce 100644 --- a/node_package/src/handleError.js +++ b/node_package/src/handleError.js @@ -35,7 +35,7 @@ component \'${name}\' is not a generator function.\n${lastLine}`; return msg; } -export default (options) => { +const handleError = (options) => { const { e, jsCode, serverSide } = options; console.error('Exception in rendering!'); @@ -64,3 +64,5 @@ ${e.stack}`; return ReactDOMServer.renderToString(reactElement); } }; + +export default handleError; From c98e25baf649bd05f74fc0f3af20f2975fac94cc Mon Sep 17 00:00:00 2001 From: Sergey Tarasov Date: Fri, 19 Aug 2016 13:17:34 +0300 Subject: [PATCH 4/4] updated CHANGELOG --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 77b4b6142..eda59f3ef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ Contributors: please follow the recommendations outlined at [keepachangelog.com] - React on Rails now correctly parses single-digit version strings from package.json [#491](https://github.com/shakacode/react_on_rails/pull/491) by [samphilipd ](https://github.com/samphilipd ). - Fixed assets symlinking to correctly use filenames with spaces. Begining in [#510](https://github.com/shakacode/react_on_rails/pull/510), ending in [#513](https://github.com/shakacode/react_on_rails/pull/513) by [dzirtusss](https://github.com/dzirtusss) - Added authenticityToken() and authenticityHeaders() javascript helpers for easier use when working with CSRF protection tag generated by Rails [#517](https://github.com/shakacode/react_on_rails/pull/517) by [dzirtusss](https://github.com/dzirtusss) +- Updated JavaScript error handling on the client side from catching internally to passing through to the browser [#521](https://github.com/shakacode/react_on_rails/pull/521) by [dzirtusss](https://github.com/dzirtusss) + ## [6.0.5] - 2016-07-11 ##### Added