From 2b14d181462cad8359da4fa6bc6dfda0f742c398 Mon Sep 17 00:00:00 2001 From: Tim Date: Thu, 18 Jul 2024 15:33:11 +1200 Subject: [PATCH] fix YieldableError rendering on bun (#3295) --- .changeset/unlucky-peaches-report.md | 5 +++++ packages/effect/src/internal/core.ts | 12 ++++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) create mode 100644 .changeset/unlucky-peaches-report.md diff --git a/.changeset/unlucky-peaches-report.md b/.changeset/unlucky-peaches-report.md new file mode 100644 index 0000000000..026077e9a4 --- /dev/null +++ b/.changeset/unlucky-peaches-report.md @@ -0,0 +1,5 @@ +--- +"effect": patch +--- + +fix YieldableError rendering on bun diff --git a/packages/effect/src/internal/core.ts b/packages/effect/src/internal/core.ts index f33a15c022..d0ae961aca 100644 --- a/packages/effect/src/internal/core.ts +++ b/packages/effect/src/internal/core.ts @@ -29,7 +29,7 @@ import type * as MetricLabel from "../MetricLabel.js" import * as MutableRef from "../MutableRef.js" import * as Option from "../Option.js" import { pipeArguments } from "../Pipeable.js" -import { hasProperty, isObject, isPromiseLike, isString, type Predicate, type Refinement } from "../Predicate.js" +import { hasProperty, isObject, isPromiseLike, type Predicate, type Refinement } from "../Predicate.js" import type * as Request from "../Request.js" import type * as BlockedRequests from "../RequestBlock.js" import type * as RequestResolver from "../RequestResolver.js" @@ -2186,6 +2186,8 @@ export const YieldableError: new(message?: string, options?: ErrorOptions) => Ca [NodeInspectSymbol]() { if (this.toString !== globalThis.Error.prototype.toString) { return this.stack ? `${this.toString()}\n${this.stack.split("\n").slice(1).join("\n")}` : this.toString() + } else if ("Bun" in globalThis) { + return internalCause.pretty(internalCause.fail(this), { renderErrorCause: true }) } return this } @@ -2311,12 +2313,14 @@ export const UnknownExceptionTypeId: Cause.UnknownExceptionTypeId = Symbol.for( ) as Cause.UnknownExceptionTypeId /** @internal */ -export const UnknownException: new(error: unknown, message?: string | undefined) => Cause.UnknownException = +export const UnknownException: new(cause: unknown, message?: string | undefined) => Cause.UnknownException = (function() { class UnknownException extends YieldableError { readonly _tag = "UnknownException" - constructor(readonly error: unknown, message?: string) { - super(message ?? (hasProperty(error, "message") && isString(error.message) ? error.message : void 0)) + readonly error: unknown + constructor(readonly cause: unknown, message?: string) { + super(message ?? "An unknown error occurred", { cause }) + this.error = cause } } Object.assign(UnknownException.prototype, {