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

Only log partytown setup error once (#93378)

parent acb41ed6
......@@ -56,7 +56,6 @@ fn is_error_class_name(name: &str) -> bool {
|| name == "DecodeError"
|| name == "DynamicServerError"
|| name == "ExportError"
|| name == "FatalError"
|| name == "ImageError"
|| name == "InstantValidationError"
|| name == "InvariantError"
......
export class FatalError extends Error {}
......@@ -3,7 +3,6 @@ import os from 'os'
import path from 'path'
import semver from 'next/dist/compiled/semver'
import { FatalError } from '../fatal-error'
import isError from '../is-error'
function resolvePathAliasTarget(baseUrl: string, target: string): string {
......@@ -92,9 +91,7 @@ export async function getTypeScriptConfiguration(
typescript.sys.readFile
)
if (error) {
throw new FatalError(
typescript.formatDiagnostic(error, formatDiagnosticsHost)
)
throw new Error(typescript.formatDiagnostic(error, formatDiagnosticsHost))
}
let configToParse: any = config
......@@ -185,7 +182,8 @@ export async function getTypeScriptConfiguration(
}
if (result.errors?.length) {
throw new FatalError(
// TODO: Throw AggregateError for all diagnostics.
throw new Error(
typescript.formatDiagnostic(result.errors[0], formatDiagnosticsHost)
)
}
......@@ -194,7 +192,7 @@ export async function getTypeScriptConfiguration(
} catch (err) {
if (isError(err) && err.name === 'SyntaxError') {
const reason = '\n' + (err.message ?? '')
throw new FatalError(
throw new Error(
bold(
'Could not parse' +
cyan('tsconfig.json') +
......
......@@ -2,7 +2,6 @@ import { bold, cyan, red } from '../picocolors'
import { getOxfordCommaList } from '../oxford-comma-list'
import type { MissingDependency } from '../has-necessary-dependencies'
import { FatalError } from '../fatal-error'
import { getPkgManager } from '../helpers/get-pkg-manager'
export function missingDepsError(
......@@ -21,7 +20,7 @@ export function missingDepsError(
' file from your package root (and any TypeScript files in your app and pages directories).'
)
throw new FatalError(
throw new Error(
bold(
red(
`It looks like you're trying to use TypeScript but do not have the required package(s) installed.`
......
......@@ -5,14 +5,13 @@ import path from 'path'
import { hasNecessaryDependencies } from './has-necessary-dependencies'
import type { NecessaryDependencies } from './has-necessary-dependencies'
import { fileExists, FileType } from './file-exists'
import { FatalError } from './fatal-error'
import * as Log from '../build/output/log'
import { getPkgManager } from './helpers/get-pkg-manager'
async function missingDependencyError(dir: string) {
const packageManager = getPkgManager(dir)
throw new FatalError(
throw new Error(
bold(
red(
"It looks like you're trying to use Partytown with next/script but do not have the required package(s) installed."
......@@ -65,35 +64,25 @@ export async function verifyPartytownSetup(
dir: string,
targetDir: string
): Promise<void> {
try {
const partytownDeps: NecessaryDependencies = hasNecessaryDependencies(dir, [
{
file: '@builder.io/partytown',
pkg: '@builder.io/partytown',
exportsRestrict: false,
},
])
const partytownDeps: NecessaryDependencies = hasNecessaryDependencies(dir, [
{
file: '@builder.io/partytown',
pkg: '@builder.io/partytown',
exportsRestrict: false,
},
])
if (partytownDeps.missing?.length > 0) {
await missingDependencyError(dir)
} else {
try {
await copyPartytownStaticFiles(partytownDeps, targetDir)
} catch (err) {
Log.warn(
`Partytown library files could not be copied to the static directory. Please ensure that ${bold(
cyan('@builder.io/partytown')
)} is installed as a dependency.`
)
}
}
} catch (err) {
// Don't show a stack trace when there is an error due to missing dependencies
if (err instanceof FatalError) {
console.error(err.message)
// Throw to allow finally blocks to run (e.g., telemetry flush)
throw err
if (partytownDeps.missing?.length > 0) {
await missingDependencyError(dir)
} else {
try {
await copyPartytownStaticFiles(partytownDeps, targetDir)
} catch (err) {
Log.warn(
`Partytown library files could not be copied to the static directory. Please ensure that ${bold(
cyan('@builder.io/partytown')
)} is installed as a dependency.`
)
}
throw err
}
}
......@@ -243,7 +243,6 @@ async function readNormalizedNFT(next, name) {
"/node_modules/next/dist/lib/download-swc.js",
"/node_modules/next/dist/lib/error-telemetry-utils.js",
"/node_modules/next/dist/lib/fallback.js",
"/node_modules/next/dist/lib/fatal-error.js",
"/node_modules/next/dist/lib/file-exists.js",
"/node_modules/next/dist/lib/find-config.js",
"/node_modules/next/dist/lib/find-pages-dir.js",
......
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