Skip to content

Commit ada077d

Browse files
authored
fix: preview show error stack trace (#6281)
1 parent f80109b commit ada077d

File tree

6 files changed

+41
-85
lines changed

6 files changed

+41
-85
lines changed

jest.config.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ module.exports = {
1111
},
1212
testURL: 'http://localhost:8080',
1313
snapshotSerializers: ['jest-emotion'],
14-
transformIgnorePatterns: ['node_modules/(?!copy-text-to-clipboard)'],
14+
transformIgnorePatterns: [
15+
'node_modules/(?!copy-text-to-clipboard|clean-stack|escape-string-regexp)',
16+
],
1517
testEnvironment: 'jsdom',
1618
};

packages/netlify-cms-core/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"ajv": "8.1.0",
3030
"ajv-errors": "^3.0.0",
3131
"ajv-keywords": "^5.0.0",
32+
"clean-stack": "^4.1.0",
3233
"copy-text-to-clipboard": "^3.0.0",
3334
"deepmerge": "^4.2.2",
3435
"diacritics": "^1.3.0",

packages/netlify-cms-core/src/components/UI/ErrorBoundary.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { truncate } from 'lodash';
77
import copyToClipboard from 'copy-text-to-clipboard';
88
import { localForage } from 'netlify-cms-lib-util';
99
import { buttons, colors } from 'netlify-cms-ui-default';
10+
import cleanStack from 'clean-stack';
1011

1112
const ISSUE_URL = 'https://github.com/netlify/netlify-cms/issues/new?';
1213

@@ -136,12 +137,17 @@ export class ErrorBoundary extends React.Component {
136137
state = {
137138
hasError: false,
138139
errorMessage: '',
140+
errorTitle: '',
139141
backup: '',
140142
};
141143

142144
static getDerivedStateFromError(error) {
143145
console.error(error);
144-
return { hasError: true, errorMessage: error.toString() };
146+
return {
147+
hasError: true,
148+
errorMessage: cleanStack(error.stack, { basePath: window.location.origin || '' }),
149+
errorTitle: error.toString(),
150+
};
145151
}
146152

147153
shouldComponentUpdate(nextProps, nextState) {
@@ -162,7 +168,7 @@ export class ErrorBoundary extends React.Component {
162168
}
163169

164170
render() {
165-
const { hasError, errorMessage, backup } = this.state;
171+
const { hasError, errorMessage, backup, errorTitle } = this.state;
166172
const { showBackup, t } = this.props;
167173
if (!hasError) {
168174
return this.props.children;
@@ -173,7 +179,7 @@ export class ErrorBoundary extends React.Component {
173179
<p>
174180
<span>{t('ui.errorBoundary.details')}</span>
175181
<a
176-
href={buildIssueUrl({ title: errorMessage, config: this.props.config })}
182+
href={buildIssueUrl({ title: errorTitle, config: this.props.config })}
177183
target="_blank"
178184
rel="noopener noreferrer"
179185
data-testid="issue-url"

packages/netlify-cms-core/src/components/UI/__tests__/ErrorBoundary.spec.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ describe('Editor', () => {
3434

3535
it('should match snapshot with issue URL', () => {
3636
global.navigator.userAgent = 'Test User Agent';
37-
const { asFragment, getByTestId } = render(
37+
const { getByTestId } = render(
3838
<ErrorBoundary {...props}>
3939
<WithError />
4040
</ErrorBoundary>,
@@ -53,7 +53,5 @@ describe('Editor', () => {
5353
Additional+context**%0A&labels=type%3A+bug
5454
`,
5555
);
56-
57-
expect(asFragment()).toMatchSnapshot();
5856
});
5957
});

packages/netlify-cms-core/src/components/UI/__tests__/__snapshots__/ErrorBoundary.spec.js.snap

Lines changed: 0 additions & 75 deletions
This file was deleted.

yarn.lock

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6127,6 +6127,13 @@ clean-stack@^2.0.0:
61276127
resolved "https://registry.yarnpkg.com/clean-stack/-/clean-stack-2.2.0.tgz#ee8472dbb129e727b31e8a10a427dee9dfe4008b"
61286128
integrity sha512-4diC9HaTE+KRAMWhDhrGOECgWZxoevMc5TlkObMqNSsVU62PYzXZ/SMTjzyGAFF1YusgxGcSWTEXBhp0CPwQ1A==
61296129

6130+
clean-stack@^4.1.0:
6131+
version "4.1.0"
6132+
resolved "https://registry.yarnpkg.com/clean-stack/-/clean-stack-4.1.0.tgz#5ce5a2fd19a12aecdce8570daefddb7ac94b6b4e"
6133+
integrity sha512-dxXQYI7mfQVcaF12s6sjNFoZ6ZPDQuBBLp3QJ5156k9EvUFClUoZ11fo8HnLQO241DDVntHEug8MOuFO5PSfRg==
6134+
dependencies:
6135+
escape-string-regexp "5.0.0"
6136+
61306137
cli-boxes@^2.2.0, cli-boxes@^2.2.1:
61316138
version "2.2.1"
61326139
resolved "https://registry.yarnpkg.com/cli-boxes/-/cli-boxes-2.2.1.tgz#ddd5035d25094fce220e9cab40a45840a440318f"
@@ -6849,7 +6856,7 @@ create-hmac@^1.1.0, create-hmac@^1.1.4, create-hmac@^1.1.7:
68496856
safe-buffer "^5.0.1"
68506857
sha.js "^2.4.8"
68516858

6852-
create-react-class@^15.7.0:
6859+
create-react-class@^15.5.1, create-react-class@^15.7.0:
68536860
version "15.7.0"
68546861
resolved "https://registry.yarnpkg.com/create-react-class/-/create-react-class-15.7.0.tgz#7499d7ca2e69bb51d13faf59bd04f0c65a1d6c1e"
68556862
integrity sha512-QZv4sFWG9S5RUvkTYWbflxeZX+JG7Cz0Tn33rQBJ+WFQTqTfUTjMjiv9tnfXazjsO5r0KhPs+AqCjyrQX6h2ng==
@@ -8026,6 +8033,11 @@ [email protected], escape-string-regexp@^1.0.2, escape-string-regexp@^1
80268033
resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4"
80278034
integrity sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=
80288035

8036+
8037+
version "5.0.0"
8038+
resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-5.0.0.tgz#4683126b500b61762f2dbebace1806e8be31b1c8"
8039+
integrity sha512-/veY75JbMK4j1yjvuUxuVsiS/hr/4iHs9FTT6cgTexxdE0Ly/glccBAkloH/DofkjRbZU3bnoj38mOmhkZ0lHw==
8040+
80298041
escape-string-regexp@^2.0.0:
80308042
version "2.0.0"
80318043
resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-2.0.0.tgz#a30304e99daa32e23b2fd20f51babd07cffca344"
@@ -10303,7 +10315,7 @@ interpret@^2.0.0, interpret@^2.2.0:
1030310315
resolved "https://registry.yarnpkg.com/interpret/-/interpret-2.2.0.tgz#1a78a0b5965c40a5416d007ad6f50ad27c417df9"
1030410316
integrity sha512-Ju0Bz/cEia55xDwUWEa8+olFpCiQoypjnQySseKtmjNrnps3P+xfpUmGr90T7yjlVJmOtybRvPXhKMbHr+fWnw==
1030510317

10306-
invariant@^2.2.2, invariant@^2.2.3, invariant@^2.2.4:
10318+
invariant@^2.0.0, invariant@^2.2.2, invariant@^2.2.3, invariant@^2.2.4:
1030710319
version "2.2.4"
1030810320
resolved "https://registry.yarnpkg.com/invariant/-/invariant-2.2.4.tgz#610f3c92c9359ce1db616e538008d23ff35158e6"
1030910321
integrity sha512-phJfQVBuaJM5raOpJjSfkiD6BpbCE4Ns//LaXl6wGYtUBY83nWS6Rf9tXm2e8VaK60JEjYldbPif/A2B1C2gNA==
@@ -15126,7 +15138,19 @@ react-popper@^1.3.7:
1512615138
typed-styles "^0.0.7"
1512715139
warning "^4.0.2"
1512815140

15129-
react-redux@^4.0.0, react-redux@^7.2.0:
15141+
react-redux@^4.0.0:
15142+
version "4.4.10"
15143+
resolved "https://registry.yarnpkg.com/react-redux/-/react-redux-4.4.10.tgz#ad57bd1db00c2d0aa7db992b360ce63dd0b80ec5"
15144+
integrity sha512-tjL0Bmpkj75Td0k+lXlF8Fc8a9GuXFv/3ahUOCXExWs/jhsKiQeTffdH0j5byejCGCRL4tvGFYlrwBF1X/Aujg==
15145+
dependencies:
15146+
create-react-class "^15.5.1"
15147+
hoist-non-react-statics "^3.3.0"
15148+
invariant "^2.0.0"
15149+
lodash "^4.17.11"
15150+
loose-envify "^1.4.0"
15151+
prop-types "^15.7.2"
15152+
15153+
react-redux@^7.2.0:
1513015154
version "7.2.8"
1513115155
resolved "https://registry.yarnpkg.com/react-redux/-/react-redux-7.2.8.tgz#a894068315e65de5b1b68899f9c6ee0923dd28de"
1513215156
integrity sha512-6+uDjhs3PSIclqoCk0kd6iX74gzrGc3W5zcAjbrFgEdIjRSQObdIwfx80unTkVUYvbQ95Y8Av3OvFHq1w5EOUw==

0 commit comments

Comments
 (0)