Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@
*.lockb binary diff=lockb

.vscode/launch.json linguist-generated
src/api/schema.d.ts linguist-generated
fixture.*.c linguist-generated
src/api/schema.js linguist-generated
*-fixture* linguist-generated
src/jsc/bindings/ZigGeneratedCode.h linguist-generated
src/jsc/bindings/ZigGeneratedCode.cpp linguist-generated
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ sign.json
src/bake/generated.ts
src/jsc/bindings-obj
src/bun.js/debug-bindings-obj
src/fallback.version
src/js/out/DebugPath.h
src/js/out/functions*
src/js/out/modules*
Expand Down
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 2 additions & 41 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"esbuild": "^0.21.5",
"mitata": "^0.1.14",
"oxlint": "1.70.0",
"peechy": "0.4.34",
"prettier": "^3.6.2",
"prettier-plugin-organize-imports": "^4.3.0",
"react": "^18.3.1",
Expand Down
90 changes: 15 additions & 75 deletions packages/bun-error/index.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,18 @@
import type { JSX } from "preact";
import { createContext, render } from "preact";
import { useCallback, useContext, useEffect, useRef, useState } from "preact/hooks";
import type {
FallbackMessageContainer,
JSException,
JSException as JSExceptionType,
Location,
Message,
SourceLine,
StackFrame,
WebsocketMessageBuildFailure,
} from "../../src/api/schema";
import { messagesToMarkdown, problemsToMarkdown, withBunInfo } from "./markdown";
import { problemsToMarkdown, withBunInfo } from "./markdown";
import {
StackFrameScope,
type FallbackMessageContainer,
type JSException as JSExceptionType,
type Location,
type Message,
type SourceLine,
type StackFrame,
} from "./schema";
import { fetchAllMappings, remapPosition, sourceMappings } from "./sourcemap";

export enum StackFrameScope {
Eval = 1,
Module = 2,
Function = 3,
Global = 4,
Wasm = 5,
Constructor = 6,
}

export enum JSErrorCode {
Error = 0,
EvalError = 1,
Expand Down Expand Up @@ -225,7 +215,7 @@ const srcFileURL = (filename: string, line?: number, column?: number): string =>
};

class FancyTypeError {
constructor(exception: JSException) {
constructor(exception: JSExceptionType) {
this.runtimeType = exception.runtime_type || 0;
this.runtimeTypeName = RuntimeType[this.runtimeType] || "undefined";
this.message = exception.message || "";
Expand All @@ -239,7 +229,7 @@ class FancyTypeError {
runtimeTypeName: string;
message: string;

normalize(exception: JSException) {
normalize(exception: JSExceptionType) {
if (!exception.message) return;
const i = exception.message.lastIndexOf(" is ");
if (i === -1) return;
Expand Down Expand Up @@ -317,7 +307,7 @@ const AsyncSourceLines = ({
}: {
highlight: number;
highlightColumnStart: number;
highlightColumnEnd: number;
highlightColumnEnd?: number;
children?: any;
buildURL: (line?: number, column?: number) => string;
sourceLines: SourceLine[];
Expand Down Expand Up @@ -432,7 +422,7 @@ const SourceLines = ({
sourceLines: SourceLine[];
highlight: number;
highlightColumnStart: number;
highlightColumnEnd: number;
highlightColumnEnd?: number;
children?: any;
buildURL: (line?: number, column?: number) => string;
}) => {
Expand Down Expand Up @@ -922,11 +912,7 @@ const ResolveError = ({ message }: { message: Message }) => {
</div>
);
};
const OverlayMessageContainer = ({
problems,
reason,
isClient = false,
}: FallbackMessageContainer & { isClient: boolean }) => {
const OverlayMessageContainer = ({ problems, isClient = false }: FallbackMessageContainer & { isClient: boolean }) => {
const errorCount = problems ? problems.exceptions.length + problems.build.errors : 0;
return (
<div id="BunErrorOverlay-container">
Expand Down Expand Up @@ -982,29 +968,6 @@ const Footer = ({ toMarkdown, data }) => (
</div>
);

const BuildFailureMessageContainer = ({ messages }: { messages: Message[] }) => {
return (
<div id="BunErrorOverlay-container">
<div className="BunError-content">
<div className="BunError-header">
<Summary onClose={dismissError} errorCount={messages.length} />
</div>
<div className={`BunError-list`}>
{messages.map((buildMessage, index) => {
if (buildMessage.on.build) {
return <BuildError key={index} message={buildMessage} />;
} else if (buildMessage.on.resolve) {
return <ResolveError key={index} message={buildMessage} />;
} else {
throw new Error("Unknown build message type");
}
})}
</div>
<Footer toMarkdown={messagesToMarkdown} data={messages} />
</div>
</div>
);
};
export var thisCwd = "";
const ErrorGroupContext = createContext<{ cwd?: string }>({ cwd: undefined });
var reactRoot;
Expand Down Expand Up @@ -1034,12 +997,6 @@ function renderWithFunc(func) {
fallbackStyleSheet.remove();
shadowRoot.appendChild(fallbackStyleSheet);
reactRoot.classList.add("BunErrorRoot--FullPage");

const page = document.querySelector("style[data-bun-error-page-style]");
if (page) {
page.remove();
shadowRoot.appendChild(page);
}
}

shadowRoot.appendChild(reactRoot);
Expand All @@ -1055,9 +1012,6 @@ export function renderFallbackError(fallback: FallbackMessageContainer) {
if (fallback && fallback.cwd) {
thisCwd = fallback.cwd;
}
// Not an error
if (fallback?.problems?.name === "JSDisabled") return;

return renderWithFunc(() => (
<ErrorGroupContext.Provider value={fallback}>
<OverlayMessageContainer isClient {...fallback} />
Expand Down Expand Up @@ -1152,8 +1106,6 @@ export function renderRuntimeError(error: Error) {
errors: 0,
msgs: [],
},
code: 0,
name: error.name,
exceptions: [exception],
},
};
Expand Down Expand Up @@ -1254,15 +1206,3 @@ export function dismissError() {
while (pending.length > 0) pending.shift().stopped = true;
}
}

export const renderBuildFailure = (failure: WebsocketMessageBuildFailure, cwd: string) => {
thisCwd = cwd;
renderWithFunc(() => (
<ErrorGroupContext.Provider value={{ cwd }}>
<BuildFailureMessageContainer messages={failure.log.msgs} />
</ErrorGroupContext.Provider>
));
};

export const clearBuildFailure = dismissError;
globalThis.__BunClearBuildFailure = dismissError;
Loading