Unverified Commit aa6d7c22 authored by Sebastian "Sebbie" Silbermann's avatar Sebastian "Sebbie" Silbermann Committed by GitHub

[devtools] Omit empty looking error messages (#90256)

If the trimmed error message has no length, we skip the line entirely to remove useless vertical space from the Redbox. Errors with no messages are assumed to only be relevant due to their stack.
parent 19dcd133
...@@ -19,6 +19,10 @@ export function ErrorMessage({ errorMessage, errorType }: ErrorMessageProps) { ...@@ -19,6 +19,10 @@ export function ErrorMessage({ errorMessage, errorType }: ErrorMessageProps) {
} }
}, [errorMessage]) }, [errorMessage])
if (!errorMessage) {
return null
}
// The "Blocking Route" error message is specifically formatted to look nice // The "Blocking Route" error message is specifically formatted to look nice
// in the overlay (rather than just passed through from the console), so we // in the overlay (rather than just passed through from the console), so we
// intentionally don't truncate it and rely on the scroll overflow instead. // intentionally don't truncate it and rely on the scroll overflow instead.
......
...@@ -55,6 +55,11 @@ function GenericErrorDescription({ error }: { error: Error }) { ...@@ -55,6 +55,11 @@ function GenericErrorDescription({ error }: { error: Error }) {
message = message.slice(envPrefix.length) message = message.slice(envPrefix.length)
} }
message = message.trim()
if (!message) {
return null
}
return ( return (
<> <>
<HotlinkedText text={message} matcher={matchLinkType} /> <HotlinkedText text={message} matcher={matchLinkType} />
......
...@@ -11,6 +11,7 @@ type ErrorCauseProps = { ...@@ -11,6 +11,7 @@ type ErrorCauseProps = {
export function ErrorCause({ cause, dialogResizerRef }: ErrorCauseProps) { export function ErrorCause({ cause, dialogResizerRef }: ErrorCauseProps) {
const frames = React.use(cause.frames()) const frames = React.use(cause.frames())
const trimmedMessage = cause.error.message.trim()
const firstFrame = useMemo(() => { const firstFrame = useMemo(() => {
const index = frames.findIndex( const index = frames.findIndex(
...@@ -29,7 +30,9 @@ export function ErrorCause({ cause, dialogResizerRef }: ErrorCauseProps) { ...@@ -29,7 +30,9 @@ export function ErrorCause({ cause, dialogResizerRef }: ErrorCauseProps) {
Caused by: {cause.error.name || 'Error'} Caused by: {cause.error.name || 'Error'}
</span> </span>
</div> </div>
<p className="error-cause-message">{cause.error.message}</p> {trimmedMessage ? (
<p className="error-cause-message">{trimmedMessage}</p>
) : null}
{firstFrame && ( {firstFrame && (
<CodeFrame <CodeFrame
......
...@@ -96,7 +96,6 @@ describe('instant validation causes', () => { ...@@ -96,7 +96,6 @@ describe('instant validation causes', () => {
"cause": [ "cause": [
{ {
"label": "Caused by: Instant Validation", "label": "Caused by: Instant Validation",
"message": " ",
"source": "app/named-export/page.tsx (3:26) @ unstable_instant "source": "app/named-export/page.tsx (3:26) @ unstable_instant
> 3 | const unstable_instant = { prefetch: 'static' } > 3 | const unstable_instant = { prefetch: 'static' }
| ^", | ^",
...@@ -141,7 +140,6 @@ describe('instant validation causes', () => { ...@@ -141,7 +140,6 @@ describe('instant validation causes', () => {
"cause": [ "cause": [
{ {
"label": "Caused by: Instant Validation", "label": "Caused by: Instant Validation",
"message": " ",
"source": "app/aliased-export/page.tsx (3:17) @ unstable_instant "source": "app/aliased-export/page.tsx (3:17) @ unstable_instant
> 3 | const instant = { prefetch: 'static' } > 3 | const instant = { prefetch: 'static' }
| ^", | ^",
...@@ -186,7 +184,6 @@ describe('instant validation causes', () => { ...@@ -186,7 +184,6 @@ describe('instant validation causes', () => {
"cause": [ "cause": [
{ {
"label": "Caused by: Instant Validation", "label": "Caused by: Instant Validation",
"message": " ",
"source": "app/reexport/page.tsx (3:10) @ unstable_instant "source": "app/reexport/page.tsx (3:10) @ unstable_instant
> 3 | export { unstable_instant } from './config' > 3 | export { unstable_instant } from './config'
| ^", | ^",
...@@ -234,7 +231,6 @@ describe('instant validation causes', () => { ...@@ -234,7 +231,6 @@ describe('instant validation causes', () => {
"cause": [ "cause": [
{ {
"label": "Caused by: Instant Validation", "label": "Caused by: Instant Validation",
"message": " ",
"source": "app/indirect-export/page.tsx (4:17) @ unstable_instant "source": "app/indirect-export/page.tsx (4:17) @ unstable_instant
> 4 | const instant = _instant > 4 | const instant = _instant
| ^", | ^",
......
...@@ -189,7 +189,6 @@ describe('instant validation', () => { ...@@ -189,7 +189,6 @@ describe('instant validation', () => {
"cause": [ "cause": [
{ {
"label": "Caused by: Instant Validation", "label": "Caused by: Instant Validation",
"message": " ",
"source": "app/suspense-in-root/static/missing-suspense-around-runtime/page.tsx (3:33) @ unstable_instant "source": "app/suspense-in-root/static/missing-suspense-around-runtime/page.tsx (3:33) @ unstable_instant
> 3 | export const unstable_instant = { prefetch: 'static' } > 3 | export const unstable_instant = { prefetch: 'static' }
| ^", | ^",
...@@ -234,7 +233,6 @@ describe('instant validation', () => { ...@@ -234,7 +233,6 @@ describe('instant validation', () => {
"cause": [ "cause": [
{ {
"label": "Caused by: Instant Validation", "label": "Caused by: Instant Validation",
"message": " ",
"source": "app/suspense-in-root/static/missing-suspense-around-dynamic/page.tsx (3:33) @ unstable_instant "source": "app/suspense-in-root/static/missing-suspense-around-dynamic/page.tsx (3:33) @ unstable_instant
> 3 | export const unstable_instant = { prefetch: 'static' } > 3 | export const unstable_instant = { prefetch: 'static' }
| ^", | ^",
...@@ -277,7 +275,6 @@ describe('instant validation', () => { ...@@ -277,7 +275,6 @@ describe('instant validation', () => {
"cause": [ "cause": [
{ {
"label": "Caused by: Instant Validation", "label": "Caused by: Instant Validation",
"message": " ",
"source": "app/suspense-in-root/runtime/missing-suspense-around-dynamic/page.tsx (4:33) @ unstable_instant "source": "app/suspense-in-root/runtime/missing-suspense-around-dynamic/page.tsx (4:33) @ unstable_instant
> 4 | export const unstable_instant = { > 4 | export const unstable_instant = {
| ^", | ^",
...@@ -322,7 +319,6 @@ describe('instant validation', () => { ...@@ -322,7 +319,6 @@ describe('instant validation', () => {
"cause": [ "cause": [
{ {
"label": "Caused by: Instant Validation", "label": "Caused by: Instant Validation",
"message": " ",
"source": "app/suspense-in-root/static/missing-suspense-around-dynamic-layout/layout.tsx (4:33) @ unstable_instant "source": "app/suspense-in-root/static/missing-suspense-around-dynamic-layout/layout.tsx (4:33) @ unstable_instant
> 4 | export const unstable_instant = { prefetch: 'static' } > 4 | export const unstable_instant = { prefetch: 'static' }
| ^", | ^",
...@@ -367,7 +363,6 @@ describe('instant validation', () => { ...@@ -367,7 +363,6 @@ describe('instant validation', () => {
"cause": [ "cause": [
{ {
"label": "Caused by: Instant Validation", "label": "Caused by: Instant Validation",
"message": " ",
"source": "app/suspense-in-root/runtime/missing-suspense-around-dynamic-layout/layout.tsx (4:33) @ unstable_instant "source": "app/suspense-in-root/runtime/missing-suspense-around-dynamic-layout/layout.tsx (4:33) @ unstable_instant
> 4 | export const unstable_instant = { > 4 | export const unstable_instant = {
| ^", | ^",
...@@ -411,7 +406,6 @@ describe('instant validation', () => { ...@@ -411,7 +406,6 @@ describe('instant validation', () => {
"cause": [ "cause": [
{ {
"label": "Caused by: Instant Validation", "label": "Caused by: Instant Validation",
"message": " ",
"source": "app/suspense-in-root/static/missing-suspense-around-params/[param]/page.tsx (1:33) @ unstable_instant "source": "app/suspense-in-root/static/missing-suspense-around-params/[param]/page.tsx (1:33) @ unstable_instant
> 1 | export const unstable_instant = { prefetch: 'static' } > 1 | export const unstable_instant = { prefetch: 'static' }
| ^", | ^",
...@@ -465,7 +459,6 @@ describe('instant validation', () => { ...@@ -465,7 +459,6 @@ describe('instant validation', () => {
"cause": [ "cause": [
{ {
"label": "Caused by: Instant Validation", "label": "Caused by: Instant Validation",
"message": " ",
"source": "app/suspense-in-root/static/missing-suspense-around-search-params/page.tsx (1:33) @ unstable_instant "source": "app/suspense-in-root/static/missing-suspense-around-search-params/page.tsx (1:33) @ unstable_instant
> 1 | export const unstable_instant = { prefetch: 'static' } > 1 | export const unstable_instant = { prefetch: 'static' }
| ^", | ^",
...@@ -532,7 +525,6 @@ describe('instant validation', () => { ...@@ -532,7 +525,6 @@ describe('instant validation', () => {
"cause": [ "cause": [
{ {
"label": "Caused by: Instant Validation", "label": "Caused by: Instant Validation",
"message": " ",
"source": "app/suspense-in-root/static/suspense-too-high/page.tsx (3:33) @ unstable_instant "source": "app/suspense-in-root/static/suspense-too-high/page.tsx (3:33) @ unstable_instant
> 3 | export const unstable_instant = { prefetch: 'static' } > 3 | export const unstable_instant = { prefetch: 'static' }
| ^", | ^",
...@@ -577,7 +569,6 @@ describe('instant validation', () => { ...@@ -577,7 +569,6 @@ describe('instant validation', () => {
"cause": [ "cause": [
{ {
"label": "Caused by: Instant Validation", "label": "Caused by: Instant Validation",
"message": " ",
"source": "app/suspense-in-root/runtime/suspense-too-high/page.tsx (4:33) @ unstable_instant "source": "app/suspense-in-root/runtime/suspense-too-high/page.tsx (4:33) @ unstable_instant
> 4 | export const unstable_instant = { > 4 | export const unstable_instant = {
| ^", | ^",
...@@ -707,7 +698,6 @@ describe('instant validation', () => { ...@@ -707,7 +698,6 @@ describe('instant validation', () => {
"cause": [ "cause": [
{ {
"label": "Caused by: Instant Validation", "label": "Caused by: Instant Validation",
"message": " ",
"source": "app/suspense-in-root/static/invalid-only-loading-around-dynamic/page.tsx (4:33) @ unstable_instant "source": "app/suspense-in-root/static/invalid-only-loading-around-dynamic/page.tsx (4:33) @ unstable_instant
> 4 | export const unstable_instant = { prefetch: 'static' } > 4 | export const unstable_instant = { prefetch: 'static' }
| ^", | ^",
...@@ -759,7 +749,6 @@ describe('instant validation', () => { ...@@ -759,7 +749,6 @@ describe('instant validation', () => {
"cause": [ "cause": [
{ {
"label": "Caused by: Instant Validation", "label": "Caused by: Instant Validation",
"message": " ",
"source": "app/suspense-in-root/static/blocking-layout/missing-suspense-around-dynamic/page.tsx (3:33) @ unstable_instant "source": "app/suspense-in-root/static/blocking-layout/missing-suspense-around-dynamic/page.tsx (3:33) @ unstable_instant
> 3 | export const unstable_instant = { prefetch: 'static' } > 3 | export const unstable_instant = { prefetch: 'static' }
| ^", | ^",
...@@ -818,7 +807,6 @@ describe('instant validation', () => { ...@@ -818,7 +807,6 @@ describe('instant validation', () => {
"cause": [ "cause": [
{ {
"label": "Caused by: Instant Validation", "label": "Caused by: Instant Validation",
"message": " ",
"source": "app/suspense-in-root/static/invalid-blocking-inside-static/layout.tsx (1:33) @ unstable_instant "source": "app/suspense-in-root/static/invalid-blocking-inside-static/layout.tsx (1:33) @ unstable_instant
> 1 | export const unstable_instant = { prefetch: 'static' } > 1 | export const unstable_instant = { prefetch: 'static' }
| ^", | ^",
...@@ -863,7 +851,6 @@ describe('instant validation', () => { ...@@ -863,7 +851,6 @@ describe('instant validation', () => {
"cause": [ "cause": [
{ {
"label": "Caused by: Instant Validation", "label": "Caused by: Instant Validation",
"message": " ",
"source": "app/suspense-in-root/runtime/invalid-blocking-inside-runtime/layout.tsx (3:33) @ unstable_instant "source": "app/suspense-in-root/runtime/invalid-blocking-inside-runtime/layout.tsx (3:33) @ unstable_instant
> 3 | export const unstable_instant = { > 3 | export const unstable_instant = {
| ^", | ^",
...@@ -909,7 +896,6 @@ describe('instant validation', () => { ...@@ -909,7 +896,6 @@ describe('instant validation', () => {
"cause": [ "cause": [
{ {
"label": "Caused by: Instant Validation", "label": "Caused by: Instant Validation",
"message": " ",
"source": "app/suspense-in-root/static/missing-suspense-in-parallel-route/page.tsx (3:33) @ unstable_instant "source": "app/suspense-in-root/static/missing-suspense-in-parallel-route/page.tsx (3:33) @ unstable_instant
> 3 | export const unstable_instant = { prefetch: 'static' } > 3 | export const unstable_instant = { prefetch: 'static' }
| ^", | ^",
...@@ -955,7 +941,6 @@ describe('instant validation', () => { ...@@ -955,7 +941,6 @@ describe('instant validation', () => {
"cause": [ "cause": [
{ {
"label": "Caused by: Instant Validation", "label": "Caused by: Instant Validation",
"message": " ",
"source": "app/suspense-in-root/static/missing-suspense-in-parallel-route/foo/page.tsx (1:33) @ unstable_instant "source": "app/suspense-in-root/static/missing-suspense-in-parallel-route/foo/page.tsx (1:33) @ unstable_instant
> 1 | export const unstable_instant = { prefetch: 'static' } > 1 | export const unstable_instant = { prefetch: 'static' }
| ^", | ^",
...@@ -1001,7 +986,6 @@ describe('instant validation', () => { ...@@ -1001,7 +986,6 @@ describe('instant validation', () => {
"cause": [ "cause": [
{ {
"label": "Caused by: Instant Validation", "label": "Caused by: Instant Validation",
"message": " ",
"source": "app/suspense-in-root/static/missing-suspense-in-parallel-route/bar/page.tsx (1:33) @ unstable_instant "source": "app/suspense-in-root/static/missing-suspense-in-parallel-route/bar/page.tsx (1:33) @ unstable_instant
> 1 | export const unstable_instant = { prefetch: 'static' } > 1 | export const unstable_instant = { prefetch: 'static' }
| ^", | ^",
...@@ -1049,7 +1033,6 @@ describe('instant validation', () => { ...@@ -1049,7 +1033,6 @@ describe('instant validation', () => {
"cause": [ "cause": [
{ {
"label": "Caused by: Instant Validation", "label": "Caused by: Instant Validation",
"message": " ",
"source": "app/suspense-in-root/static/invalid-client-data-blocks-validation/page.tsx (1:33) @ unstable_instant "source": "app/suspense-in-root/static/invalid-client-data-blocks-validation/page.tsx (1:33) @ unstable_instant
> 1 | export const unstable_instant = { > 1 | export const unstable_instant = {
| ^", | ^",
......
...@@ -75,7 +75,7 @@ interface ErrorSnapshotOptions { ...@@ -75,7 +75,7 @@ interface ErrorSnapshotOptions {
interface SanitizedCauseEntry { interface SanitizedCauseEntry {
label: string | null label: string | null
message: string | null message?: string
source: string | null source: string | null
stack: string[] stack: string[]
} }
...@@ -83,7 +83,7 @@ interface SanitizedCauseEntry { ...@@ -83,7 +83,7 @@ interface SanitizedCauseEntry {
export interface ErrorSnapshot { export interface ErrorSnapshot {
environmentLabel: string | null environmentLabel: string | null
label: string | null label: string | null
description: string | null description?: string
componentStack?: string componentStack?: string
cause?: SanitizedCauseEntry[] cause?: SanitizedCauseEntry[]
source: string | null source: string | null
...@@ -239,11 +239,14 @@ async function createErrorSnapshot( ...@@ -239,11 +239,14 @@ async function createErrorSnapshot(
const snapshot: ErrorSnapshot = { const snapshot: ErrorSnapshot = {
environmentLabel, environmentLabel,
label: label ?? '<FIXME-excluded-label>', label: label ?? '<FIXME-excluded-label>',
description: sanitizedDescription,
source: focusedSource, source: focusedSource,
stack: sanitizeStack(stack, next), stack: sanitizeStack(stack, next),
} }
if (sanitizedDescription !== null) {
snapshot.description = sanitizedDescription
}
// Hydration diffs are only relevant to some specific errors // Hydration diffs are only relevant to some specific errors
// so we hide them from the snapshots unless they are present. // so we hide them from the snapshots unless they are present.
if (componentStack !== null) { if (componentStack !== null) {
...@@ -252,12 +255,17 @@ async function createErrorSnapshot( ...@@ -252,12 +255,17 @@ async function createErrorSnapshot(
// Error.cause chain is only relevant when present. // Error.cause chain is only relevant when present.
if (cause !== null) { if (cause !== null) {
snapshot.cause = cause.map((entry) => ({ snapshot.cause = cause.map((entry) => {
label: entry.label, const causeEntry: SanitizedCauseEntry = {
message: entry.message, label: entry.label,
source: focusSource(entry.source, next), source: focusSource(entry.source, next),
stack: sanitizeStack(entry.stack, next) ?? [], stack: sanitizeStack(entry.stack, next) ?? [],
})) }
if (entry.message !== null) {
causeEntry.message = entry.message
}
return causeEntry
})
} }
return snapshot return snapshot
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment