Skip to content

Commit b4f9898

Browse files
jackjocrossjaredpalmer
authored andcommitted
Add pretty node errors (#691)
1 parent 72934d9 commit b4f9898

File tree

4 files changed

+159
-7
lines changed

4 files changed

+159
-7
lines changed

packages/razzle-dev-utils/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@
1212
"webpackHotDevClient.js",
1313
"setPorts.js",
1414
"makeLoaderFinder.js",
15-
"WebpackConfigHelpers.js"
15+
"WebpackConfigHelpers.js",
16+
"prettyNodeErrors.js"
1617
],
1718
"dependencies": {
1819
"chalk": "1.1.3",
20+
"jest-message-util": "^23.2.0",
1921
"react-dev-utils": "4.1.0",
2022
"sockjs-client": "1.1.4",
2123
"strip-ansi": "3.0.1"
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
const {
2+
formatExecError,
3+
separateMessageFromStack,
4+
} = require('jest-message-util');
5+
6+
function pretty(error) {
7+
return `\n${formatExecError(
8+
error,
9+
{ rootDir: process.cwd() },
10+
{},
11+
undefined,
12+
true
13+
)}`;
14+
}
15+
16+
function usePrettyErrors(transform) {
17+
const { prepareStackTrace } = Error;
18+
19+
Error.prepareStackTrace = (error, trace) => {
20+
const prepared = prepareStackTrace
21+
? separateMessageFromStack(prepareStackTrace(error, trace))
22+
: error;
23+
const transformed = transform ? transform(prepared) : prepared;
24+
25+
return pretty(transformed);
26+
};
27+
}
28+
29+
// Currently needed to fix sourcemap path
30+
const stackTransform = ({ stack = '', ...rest }) => ({
31+
stack: stack.replace('/build/webpack:', ''),
32+
...rest,
33+
});
34+
35+
usePrettyErrors(stackTransform);

packages/razzle/config/createConfig.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,9 @@ module.exports = (
324324
config.watch = true;
325325
config.entry.unshift('webpack/hot/poll?300');
326326

327+
// Pretty format server errors
328+
config.entry.unshift('razzle-dev-utils/prettyNodeErrors');
329+
327330
const nodeArgs = ['-r', 'source-map-support/register'];
328331

329332
// Passthrough --inspect and --inspect-brk flags (with optional [host:port] value) to node

yarn.lock

Lines changed: 118 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
# yarn lockfile v1
33

44

5+
"@arr/every@^1.0.0":
6+
version "1.0.0"
7+
resolved "https://registry.yarnpkg.com/@arr/every/-/every-1.0.0.tgz#314f8168f50ae48a032cfdad5fdb436f464a97ac"
8+
59
610
version "7.0.0-beta.44"
711
resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.0.0-beta.44.tgz#2a02643368de80916162be70865c97774f3adbd9"
@@ -1180,6 +1184,14 @@ [email protected]:
11801184
loader-utils "^1.0.2"
11811185
mkdirp "^0.5.1"
11821186

1187+
1188+
version "7.1.4"
1189+
resolved "https://registry.yarnpkg.com/babel-loader/-/babel-loader-7.1.4.tgz#e3463938bd4e6d55d1c174c5485d406a188ed015"
1190+
dependencies:
1191+
find-cache-dir "^1.0.0"
1192+
loader-utils "^1.0.2"
1193+
mkdirp "^0.5.1"
1194+
11831195
babel-messages@^6.23.0:
11841196
version "6.23.0"
11851197
resolved "https://registry.yarnpkg.com/babel-messages/-/babel-messages-6.23.0.tgz#f3cdf4703858035b2a2951c6ec5edf6c62f2630e"
@@ -3028,7 +3040,7 @@ create-hmac@^1.1.0, create-hmac@^1.1.2, create-hmac@^1.1.4:
30283040
safe-buffer "^5.0.1"
30293041
sha.js "^2.4.8"
30303042

3031-
create-react-class@^15.6.2:
3043+
create-react-class@^15.5.1, create-react-class@^15.6.2:
30323044
version "15.6.3"
30333045
resolved "https://registry.yarnpkg.com/create-react-class/-/create-react-class-15.6.3.tgz#2d73237fb3f970ae6ebe011a9e66f46dbca80036"
30343046
dependencies:
@@ -4480,7 +4492,13 @@ file-entry-cache@^2.0.0:
44804492
flat-cache "^1.2.1"
44814493
object-assign "^4.0.1"
44824494

4483-
[email protected], [email protected], file-loader@^1.1.11:
4495+
4496+
version "0.11.2"
4497+
resolved "https://registry.yarnpkg.com/file-loader/-/file-loader-0.11.2.tgz#4ff1df28af38719a6098093b88c82c71d1794a34"
4498+
dependencies:
4499+
loader-utils "^1.0.2"
4500+
4501+
file-loader@^1.1.11:
44844502
version "1.1.11"
44854503
resolved "https://registry.yarnpkg.com/file-loader/-/file-loader-1.1.11.tgz#6fe886449b0f2a936e43cabaac0cdbfb369506f8"
44864504
dependencies:
@@ -5330,6 +5348,15 @@ [email protected]:
53305348
version "1.0.0"
53315349
resolved "https://registry.yarnpkg.com/hide-powered-by/-/hide-powered-by-1.0.0.tgz#4a85ad65881f62857fc70af7174a1184dccce32b"
53325350

5351+
history@^3.0.0:
5352+
version "3.3.0"
5353+
resolved "https://registry.yarnpkg.com/history/-/history-3.3.0.tgz#fcedcce8f12975371545d735461033579a6dae9c"
5354+
dependencies:
5355+
invariant "^2.2.1"
5356+
loose-envify "^1.2.0"
5357+
query-string "^4.2.2"
5358+
warning "^3.0.0"
5359+
53335360
history@^4.7.2:
53345361
version "4.7.2"
53355362
resolved "https://registry.yarnpkg.com/history/-/history-4.7.2.tgz#22b5c7f31633c5b8021c7f4a8a954ac139ee8d5b"
@@ -6592,6 +6619,16 @@ jest-message-util@^23.1.0:
65926619
slash "^1.0.0"
65936620
stack-utils "^1.0.1"
65946621

6622+
jest-message-util@^23.2.0:
6623+
version "23.2.0"
6624+
resolved "https://registry.yarnpkg.com/jest-message-util/-/jest-message-util-23.2.0.tgz#591e8148fff69cf89b0414809c721756ebefe744"
6625+
dependencies:
6626+
"@babel/code-frame" "^7.0.0-beta.35"
6627+
chalk "^2.0.1"
6628+
micromatch "^3.1.10"
6629+
slash "^1.0.0"
6630+
stack-utils "^1.0.1"
6631+
65956632
jest-mock@^20.0.3:
65966633
version "20.0.3"
65976634
resolved "https://registry.yarnpkg.com/jest-mock/-/jest-mock-20.0.3.tgz#8bc070e90414aa155c11a8d64c869a0d5c71da59"
@@ -7905,6 +7942,12 @@ map-visit@^1.0.0:
79057942
dependencies:
79067943
object-visit "^1.0.0"
79077944

7945+
matchit@^1.0.0:
7946+
version "1.0.6"
7947+
resolved "https://registry.yarnpkg.com/matchit/-/matchit-1.0.6.tgz#825da06468bd324f0219ebe28e12a41bfb5524c4"
7948+
dependencies:
7949+
"@arr/every" "^1.0.0"
7950+
79087951
material-ui@^1.0.0-beta.38:
79097952
version "1.0.0-beta.41"
79107953
resolved "https://registry.yarnpkg.com/material-ui/-/material-ui-1.0.0-beta.41.tgz#0869bed008caa10003ab20ea726476b560c23160"
@@ -8045,6 +8088,24 @@ micromatch@^2.1.5, micromatch@^2.3.11:
80458088
parse-glob "^3.0.4"
80468089
regex-cache "^0.4.2"
80478090

8091+
micromatch@^3.1.10:
8092+
version "3.1.10"
8093+
resolved "https://registry.yarnpkg.com/micromatch/-/micromatch-3.1.10.tgz#70859bc95c9840952f359a068a3fc49f9ecfac23"
8094+
dependencies:
8095+
arr-diff "^4.0.0"
8096+
array-unique "^0.3.2"
8097+
braces "^2.3.1"
8098+
define-property "^2.0.2"
8099+
extend-shallow "^3.0.2"
8100+
extglob "^2.0.4"
8101+
fragment-cache "^0.2.1"
8102+
kind-of "^6.0.2"
8103+
nanomatch "^1.2.9"
8104+
object.pick "^1.3.0"
8105+
regex-not "^1.0.0"
8106+
snapdragon "^0.8.1"
8107+
to-regex "^3.0.2"
8108+
80488109
micromatch@^3.1.4, micromatch@^3.1.8:
80498110
version "3.1.9"
80508111
resolved "https://registry.yarnpkg.com/micromatch/-/micromatch-3.1.9.tgz#15dc93175ae39e52e93087847096effc73efcf89"
@@ -8820,7 +8881,7 @@ parse5@^3.0.3:
88208881
dependencies:
88218882
"@types/node" "*"
88228883

8823-
parseurl@^1.3.0, parseurl@~1.3.2:
8884+
parseurl@^1.3.0, parseurl@^1.3.2, parseurl@~1.3.2:
88248885
version "1.3.2"
88258886
resolved "https://registry.yarnpkg.com/parseurl/-/parseurl-1.3.2.tgz#fc289d4ed8993119460c156253262cdc8de65bf3"
88268887

@@ -8966,6 +9027,13 @@ pn@^1.1.0:
89669027
version "1.1.0"
89679028
resolved "https://registry.yarnpkg.com/pn/-/pn-1.1.0.tgz#e2f4cef0e219f463c179ab37463e4e1ecdccbafb"
89689029

9030+
polka@^0.3.4:
9031+
version "0.3.4"
9032+
resolved "https://registry.yarnpkg.com/polka/-/polka-0.3.4.tgz#685bc3529a4582378853d568aa15d78eb3318eb3"
9033+
dependencies:
9034+
parseurl "^1.3.2"
9035+
trouter "^1.0.0"
9036+
89699037
popper.js@^1.12.9:
89709038
version "1.14.3"
89719039
resolved "https://registry.yarnpkg.com/popper.js/-/popper.js-1.14.3.tgz#1438f98d046acf7b4d78cd502bf418ac64d4f095"
@@ -9516,6 +9584,13 @@ prop-types@^15.5.0, prop-types@^15.5.10, prop-types@^15.5.4, prop-types@^15.5.8,
95169584
loose-envify "^1.3.1"
95179585
object-assign "^4.1.1"
95189586

9587+
prop-types@^15.5.6:
9588+
version "15.6.2"
9589+
resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.6.2.tgz#05d5ca77b4453e985d60fc7ff8c859094a497102"
9590+
dependencies:
9591+
loose-envify "^1.3.1"
9592+
object-assign "^4.1.1"
9593+
95199594
protobufjs@^5.0.0:
95209595
version "5.0.2"
95219596
resolved "https://registry.yarnpkg.com/protobufjs/-/protobufjs-5.0.2.tgz#59748d7dcf03d2db22c13da9feb024e16ab80c91"
@@ -9624,7 +9699,7 @@ qs@~6.4.0:
96249699
version "6.4.0"
96259700
resolved "https://registry.yarnpkg.com/qs/-/qs-6.4.0.tgz#13e26d28ad6b0ffaa91312cd3bf708ed351e7233"
96269701

9627-
query-string@^4.1.0:
9702+
query-string@^4.1.0, query-string@^4.2.2:
96289703
version "4.3.4"
96299704
resolved "https://registry.yarnpkg.com/query-string/-/query-string-4.3.4.tgz#bbb693b9ca915c232515b228b1a02b609043dbeb"
96309705
dependencies:
@@ -9990,6 +10065,30 @@ react-router-dom@^4.2.2:
999010065
react-router "^4.2.0"
999110066
warning "^3.0.0"
999210067

10068+
10069+
version "4.0.8"
10070+
resolved "https://registry.yarnpkg.com/react-router-redux/-/react-router-redux-4.0.8.tgz#227403596b5151e182377dab835b5d45f0f8054e"
10071+
10072+
10073+
version "0.4.2"
10074+
resolved "https://registry.yarnpkg.com/react-router-scroll/-/react-router-scroll-0.4.2.tgz#4b90e8707edf96eba7f066d94c5b4338bd6848b7"
10075+
dependencies:
10076+
prop-types "^15.5.6"
10077+
scroll-behavior "^0.9.3"
10078+
warning "^3.0.0"
10079+
10080+
react-router@^3.2.0:
10081+
version "3.2.1"
10082+
resolved "https://registry.yarnpkg.com/react-router/-/react-router-3.2.1.tgz#b9a3279962bdfbe684c8bd0482b81ef288f0f244"
10083+
dependencies:
10084+
create-react-class "^15.5.1"
10085+
history "^3.0.0"
10086+
hoist-non-react-statics "^2.3.1"
10087+
invariant "^2.2.1"
10088+
loose-envify "^1.2.0"
10089+
prop-types "^15.5.6"
10090+
warning "^3.0.0"
10091+
999310092
react-router@^4.2.0:
999410093
version "4.2.0"
999510094
resolved "https://registry.yarnpkg.com/react-router/-/react-router-4.2.0.tgz#61f7b3e3770daeb24062dae3eedef1b054155986"
@@ -10674,6 +10773,13 @@ schema-utils@^0.4.0, schema-utils@^0.4.3, schema-utils@^0.4.4, schema-utils@^0.4
1067410773
ajv "^6.1.0"
1067510774
ajv-keywords "^3.1.0"
1067610775

10776+
scroll-behavior@^0.9.3:
10777+
version "0.9.9"
10778+
resolved "https://registry.yarnpkg.com/scroll-behavior/-/scroll-behavior-0.9.9.tgz#ebfe0658455b82ad885b66195215416674dacce2"
10779+
dependencies:
10780+
dom-helpers "^3.2.1"
10781+
invariant "^2.2.2"
10782+
1067710783
scroll@^2.0.3:
1067810784
version "2.0.3"
1067910785
resolved "https://registry.yarnpkg.com/scroll/-/scroll-2.0.3.tgz#0951b785544205fd17753bc3d294738ba16fc2ab"
@@ -10732,7 +10838,7 @@ serve-index@^1.7.2:
1073210838
mime-types "~2.1.17"
1073310839
parseurl "~1.3.2"
1073410840

10735-
10841+
[email protected], serve-static@^1.13.2:
1073610842
version "1.13.2"
1073710843
resolved "https://registry.yarnpkg.com/serve-static/-/serve-static-1.13.2.tgz#095e8472fd5b46237db50ce486a43f4b86c6cec1"
1073810844
dependencies:
@@ -11632,7 +11738,7 @@ to-regex-range@^2.1.0:
1163211738
is-number "^3.0.0"
1163311739
repeat-string "^1.6.1"
1163411740

11635-
to-regex@^3.0.1:
11741+
to-regex@^3.0.1, to-regex@^3.0.2:
1163611742
version "3.0.2"
1163711743
resolved "https://registry.yarnpkg.com/to-regex/-/to-regex-3.0.2.tgz#13cfdd9b336552f30b51f33a8ae1b42a7a7599ce"
1163811744
dependencies:
@@ -11687,6 +11793,12 @@ trim-right@^1.0.1:
1168711793
version "1.0.1"
1168811794
resolved "https://registry.yarnpkg.com/trim-right/-/trim-right-1.0.1.tgz#cb2e1203067e0c8de1f614094b9fe45704ea6003"
1168911795

11796+
trouter@^1.0.0:
11797+
version "1.1.0"
11798+
resolved "https://registry.yarnpkg.com/trouter/-/trouter-1.1.0.tgz#ce0ad2aaa4f13af21e34785079c3352298b9259a"
11799+
dependencies:
11800+
matchit "^1.0.0"
11801+
1169011802
ts-jest@^22.4.5:
1169111803
version "22.4.6"
1169211804
resolved "https://registry.yarnpkg.com/ts-jest/-/ts-jest-22.4.6.tgz#a5d7f5e8b809626d1f4143209d301287472ec344"

0 commit comments

Comments
 (0)