Skip to content

Commit

Permalink
Use consistent error formatting in terminal
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon committed Dec 4, 2024
1 parent 432d119 commit d769733
Show file tree
Hide file tree
Showing 18 changed files with 384 additions and 575 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ async function nativeTraceSource(
return undefined
}

export async function createOriginalStackFrame(
async function createOriginalStackFrame(
project: Project,
frame: TurbopackStackFrame
): Promise<OriginalStackFrameResponse | null> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ export async function createOriginalStackFrame({
}
}

export async function getSourceMapFromCompilation(
async function getSourceMapFromCompilation(
id: string,
compilation: webpack.Compilation
): Promise<RawSourceMap | undefined> {
Expand Down
32 changes: 0 additions & 32 deletions packages/next/src/server/dev/log-app-dir-error.ts

This file was deleted.

17 changes: 7 additions & 10 deletions packages/next/src/server/dev/next-dev-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,12 +316,10 @@ export default class DevServer extends Server {
// not really errors. They're just part of rendering.
return
}
this.logErrorWithOriginalStack(reason, 'unhandledRejection').catch(
() => {}
)
this.logErrorWithOriginalStack(reason, 'unhandledRejection')
})
process.on('uncaughtException', (err) => {
this.logErrorWithOriginalStack(err, 'uncaughtException').catch(() => {})
this.logErrorWithOriginalStack(err, 'uncaughtException')
})
}

Expand Down Expand Up @@ -559,7 +557,7 @@ export default class DevServer extends Server {
} catch (error) {
const err = getProperError(error)
formatServerError(err)
this.logErrorWithOriginalStack(err).catch(() => {})
this.logErrorWithOriginalStack(err)
if (!res.sent) {
res.statusCode = 500
try {
Expand All @@ -574,11 +572,11 @@ export default class DevServer extends Server {
}
}

protected async logErrorWithOriginalStack(
protected logErrorWithOriginalStack(
err?: unknown,
type?: 'unhandledRejection' | 'uncaughtException' | 'warning' | 'app-dir'
): Promise<void> {
await this.bundlerService.logErrorWithOriginalStack(err, type)
): void {
this.bundlerService.logErrorWithOriginalStack(err, type)
}

protected getPagesManifest(): PagesManifest | undefined {
Expand Down Expand Up @@ -911,7 +909,6 @@ export default class DevServer extends Server {
await super.instrumentationOnRequestError(...args)

const err = args[0]
// Safe catch to avoid floating promises
this.logErrorWithOriginalStack(err, 'app-dir').catch(() => {})
this.logErrorWithOriginalStack(err, 'app-dir')
}
}
6 changes: 2 additions & 4 deletions packages/next/src/server/lib/dev-bundler-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,8 @@ export class DevBundlerService {
return await this.bundler.hotReloader.ensurePage(definition)
}

public logErrorWithOriginalStack: typeof this.bundler.logErrorWithOriginalStack =
async (...args) => {
return await this.bundler.logErrorWithOriginalStack(...args)
}
public logErrorWithOriginalStack =
this.bundler.logErrorWithOriginalStack.bind(this.bundler)

public async getFallbackErrorComponents(url?: string) {
await this.bundler.hotReloader.buildFallbackError()
Expand Down
7 changes: 6 additions & 1 deletion packages/next/src/server/lib/router-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import path from 'path'
import loadConfig from '../config'
import { serveStatic } from '../serve-static'
import setupDebug from 'next/dist/compiled/debug'
import * as Log from '../../build/output/log'
import { DecodeError } from '../../shared/lib/utils'
import { findPagesDir } from '../../lib/find-pages-dir'
import { setupFsCheck } from './router-utils/filesystem'
Expand Down Expand Up @@ -648,7 +649,11 @@ export async function initialize(opts: {
// not really errors. They're just part of rendering.
return
}
await developmentBundler?.logErrorWithOriginalStack(err, type)
if (type === 'unhandledRejection') {
Log.error('unhandledRejection: ', err)
} else if (type === 'uncaughtException') {
Log.error('uncaughtException: ', err)
}
}

process.on('uncaughtException', logError.bind(null, 'uncaughtException'))
Expand Down
Loading

0 comments on commit d769733

Please sign in to comment.