fix(core): better error logging on SSR/dev failures + log stacktraces and error causes (#8872)

This commit is contained in:
Sébastien Lorber 2023-04-07 18:00:59 +01:00 committed by GitHub
parent 46d2aa231d
commit a9a5f89b9f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 155 additions and 75 deletions

View file

@ -0,0 +1,46 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import React from 'react';
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
import Layout from '@theme/Layout';
// We only crash the page if siteConfig.customFields.crashTest === true
function useBoom(): boolean {
const {
siteConfig: {customFields},
} = useDocusaurusContext();
return (customFields as {crashTest?: boolean}).crashTest ?? false;
}
function boomRoot() {
throw new Error('Boom root');
}
function boomParent() {
try {
boomRoot();
} catch (err) {
throw new Error('Boom parent', {cause: err as Error});
}
}
function BoomComponent() {
const boom = useBoom();
return <>{boom && boomParent()}</>;
}
export default function CrashTestPage(): JSX.Element {
return (
<Layout>
{/* eslint-disable-next-line @docusaurus/prefer-docusaurus-heading */}
<h1>This crash if customFields.crashTest = true</h1>
<BoomComponent />
</Layout>
);
}

View file

@ -20,6 +20,7 @@ import Readme from "../README.mdx"
### Other tests
- [Crash test](/tests/pages/crashTest)
- [Code block tests](/tests/pages/code-block-tests)
- [Link tests](/tests/pages/link-tests)
- [Error boundary tests](/tests/pages/error-boundary-tests)

View file

@ -42,6 +42,11 @@ function getNextVersionName() {
*/
}
// Artificial way to crash the SSR rendering and test errors
// See website/_dogfooding/_pages tests/crashTest.tsx
// Test with: DOCUSAURUS_CRASH_TEST=true yarn build:website:fast
const crashTest = process.env.DOCUSAURUS_CRASH_TEST === 'true';
const isDev = process.env.NODE_ENV === 'development';
const isDeployPreview =
@ -139,6 +144,7 @@ const config = {
onBrokenMarkdownLinks: 'warn',
favicon: 'img/docusaurus.ico',
customFields: {
crashTest,
isDeployPreview,
description:
'An optimized site generator in React. Docusaurus helps you to move fast and write content. Build documentation websites, blogs, marketing pages, and more.',