Skip to content

Commit

Permalink
fix YieldableError rendering on bun
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-smart committed Jul 18, 2024
1 parent cc327a1 commit c6925b2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .changeset/unlucky-peaches-report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"effect": patch
---

fix YieldableError rendering on bun
26 changes: 16 additions & 10 deletions packages/effect/src/internal/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -2174,21 +2174,25 @@ export const causeSquashWith = dual<
// Errors
// -----------------------------------------------------------------------------

function customToStringRenderer(this: Cause.YieldableError) {
return this.stack ? `${this.toString()}\n${this.stack.split("\n").slice(1).join("\n")}` : this.toString()
}

/** @internal */
export const YieldableError: new(message?: string, options?: ErrorOptions) => Cause.YieldableError = (function() {
class YieldableError extends globalThis.Error {
constructor(message?: string, options?: ErrorOptions) {
super(message, options)
if (this.toString !== globalThis.Error.prototype.toString) {
;(this as any)[NodeInspectSymbol] = customToStringRenderer
}
}
commit() {
return fail(this)
}
toJSON() {
return { ...this }
}
[NodeInspectSymbol]() {
if (this.toString !== globalThis.Error.prototype.toString) {
return this.stack ? `${this.toString()}\n${this.stack.split("\n").slice(1).join("\n")}` : this.toString()
}
return this
}
}
Object.assign(YieldableError.prototype, StructuralCommitPrototype)
return YieldableError as any
Expand Down Expand Up @@ -2311,12 +2315,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, {
Expand Down

0 comments on commit c6925b2

Please sign in to comment.