Compare commits

...

1 Commits

Author SHA1 Message Date
Don Isaac
8780ec548d fix: ErrorFactory.reject() will trigger unhandled rejection event 2025-03-28 11:57:23 -07:00

View File

@@ -1,7 +1,9 @@
import path from "node:path";
import NodeErrors from "../bun.js/bindings/ErrorCode.ts";
const outputDir = process.argv[2];
const generatorName = "src/codegen/" + import.meta.file;
const outputDir = process.argv[2];
if (!outputDir) {
throw new Error("Missing output directory");
}
@@ -24,7 +26,7 @@ let zig = ``;
enumHeader = `
// clang-format off
// Generated by: src/codegen/generate-node-errors.ts
// Generated by: ${generatorName}
// Input: src/bun.js/bindings/ErrorCode.ts
#pragma once
@@ -37,7 +39,7 @@ namespace Bun {
listHeader = `
// clang-format off
// Generated by: src/codegen/generate-node-errors.ts
// Generated by: ${generatorName}
#pragma once
#include <JavaScriptCore/ErrorType.h>
@@ -51,7 +53,7 @@ static constexpr ErrorCodeData errors[${count}] = {
`;
zig = `
// Generated by: src/codegen/generate-node-errors.ts
// Generated by: ${generatorName}
const std = @import("std");
const bun = @import("root").bun;
const JSC = bun.JSC;
@@ -73,7 +75,11 @@ pub fn ErrorBuilder(comptime code: Error, comptime fmt: [:0]const u8, Args: type
/// Turn this into a JSPromise that is already rejected.
pub inline fn reject(this: @This()) JSC.JSValue {
return JSC.JSPromise.rejectedPromiseValue(this.globalThis, code.fmt(this.globalThis, fmt, this.args));
if (comptime bun.FeatureFlags.breaking_changes_1_3) {
return JSC.JSPromise.rejectedPromise(this.globalThis, code.fmt(this.globalThis, fmt, this.args)).toJS();
} else {
return JSC.JSPromise.rejectedPromiseValue(this.globalThis, code.fmt(this.globalThis, fmt, this.args));
}
}
};
}