mirror of
https://github.com/facebook/docusaurus.git
synced 2025-08-04 01:09:20 +02:00
fix(core): better error logging on SSR/dev failures + log stacktraces and error causes (#8872)
This commit is contained in:
parent
46d2aa231d
commit
a9a5f89b9f
13 changed files with 155 additions and 75 deletions
46
website/_dogfooding/_pages tests/crashTest.tsx
Normal file
46
website/_dogfooding/_pages tests/crashTest.tsx
Normal 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>
|
||||
);
|
||||
}
|
|
@ -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)
|
||||
|
|
|
@ -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.',
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue