diff --git a/packages/effect/src/Cause.ts b/packages/effect/src/Cause.ts index f41e60e91e7..8632dd4fe85 100644 --- a/packages/effect/src/Cause.ts +++ b/packages/effect/src/Cause.ts @@ -361,7 +361,6 @@ export interface Die extends Cause.Variance, Equal.Equal, Pipeable, Inspe export interface Interrupt extends Cause.Variance, Equal.Equal, Pipeable, Inspectable { readonly _tag: "Interrupt" readonly fiberId: FiberId.FiberId - readonly originSpan: Span | undefined } /** diff --git a/packages/rpc/test/Router.test.ts b/packages/rpc/test/Router.test.ts index cb75b0c956b..886506e10b0 100644 --- a/packages/rpc/test/Router.test.ts +++ b/packages/rpc/test/Router.test.ts @@ -2,13 +2,14 @@ import { RpcResolver, RpcResolverNoStream, RpcRouter } from "@effect/rpc" import * as Rpc from "@effect/rpc/Rpc" import { Schema } from "@effect/schema" import * as S from "@effect/schema/Schema" +import { it } from "@effect/vitest" import * as Array from "effect/Array" import * as Chunk from "effect/Chunk" import * as Context from "effect/Context" import * as Effect from "effect/Effect" import { flow, pipe } from "effect/Function" import * as Stream from "effect/Stream" -import { assert, describe, expect, it, test } from "vitest" +import { assert, describe, expect, test } from "vitest" interface Name { readonly _: unique symbol @@ -198,10 +199,10 @@ describe("Router", () => { value: "Hello, John!" }, { _tag: "Failure", - cause: { _tag: "Fail", error: { _tag: "SomeError", message: "fail" } } + cause: { _tag: "Annotated", cause: { _tag: "Fail", error: { _tag: "SomeError", message: "fail" } } } }, { _tag: "Failure", - cause: { _tag: "Fail", error: { _tag: "SomeError", message: "fail" } } + cause: { _tag: "Annotated", cause: { _tag: "Fail", error: { _tag: "SomeError", message: "fail" } } } }, { _tag: "Success", value: date.toISOString() @@ -247,10 +248,10 @@ describe("Router", () => { value: "Hello, John!" }, { _tag: "Failure", - cause: { _tag: "Fail", error: { _tag: "SomeError", message: "fail" } } + cause: { _tag: "Annotated", cause: { _tag: "Fail", error: { _tag: "SomeError", message: "fail" } } } }, { _tag: "Failure", - cause: { _tag: "Fail", error: { _tag: "SomeError", message: "fail" } } + cause: { _tag: "Annotated", cause: { _tag: "Fail", error: { _tag: "SomeError", message: "fail" } } } }, { _tag: "Success", value: date.toISOString() @@ -380,7 +381,7 @@ describe.each([{ ]) }).pipe(Effect.runPromise)) - test("stream fail", () => + it.effect("stream fail", () => Effect.gen(function*(_) { let n = 0 const result = yield* _( @@ -395,5 +396,5 @@ describe.each([{ ) assert.strictEqual(n, 2) assert.deepStrictEqual(result, new SomeError({ message: "fail" })) - }).pipe(Effect.runPromise)) + })) }) diff --git a/packages/schema/src/Schema.ts b/packages/schema/src/Schema.ts index 5c8e92d3ad6..c7c6592b2a7 100644 --- a/packages/schema/src/Schema.ts +++ b/packages/schema/src/Schema.ts @@ -11,6 +11,7 @@ import * as cause_ from "effect/Cause" import * as chunk_ from "effect/Chunk" import * as config_ from "effect/Config" import * as configError_ from "effect/ConfigError" +import * as context_ from "effect/Context" import * as data_ from "effect/Data" import * as dateTime from "effect/DateTime" import * as duration_ from "effect/Duration" @@ -8310,6 +8311,10 @@ export type CauseEncoded = readonly left: CauseEncoded readonly right: CauseEncoded } + | { + readonly _tag: "Annotated" + readonly cause: CauseEncoded + } const causeDieEncoded = (defect: Schema) => Struct({ @@ -8346,6 +8351,12 @@ const causeSequentialEncoded = (causeEncoded: Schema(causeEncoded: Schema, CauseEncoded, R>) => + Struct({ + _tag: Literal("Annotated"), + cause: causeEncoded + }) + const causeEncoded = ( error: Schema, defect: Schema @@ -8357,15 +8368,16 @@ const causeEncoded = ( causeDieEncoded(defect), CauseInterruptEncoded, causeSequentialEncoded(recur), - causeParallelEncoded(recur) + causeParallelEncoded(recur), + causeAnnotatedEncoded(recur) ).annotations({ title: `CauseEncoded<${format(error)}>` }) return out } -const causeArbitrary = ( +const causeEncodedArbitrary = ( error: LazyArbitrary, defect: LazyArbitrary -): LazyArbitrary> => +): LazyArbitrary> => (fc) => fc.letrec((tie) => ({ Empty: fc.record({ _tag: fc.constant("Empty" as const) }), @@ -8374,15 +8386,23 @@ const causeArbitrary = ( Interrupt: fc.record({ _tag: fc.constant("Interrupt" as const), fiberId: fiberIdArbitrary(fc) }), Sequential: fc.record({ _tag: fc.constant("Sequential" as const), left: tie("Cause"), right: tie("Cause") }), Parallel: fc.record({ _tag: fc.constant("Parallel" as const), left: tie("Cause"), right: tie("Cause") }), + Annotated: fc.record({ _tag: fc.constant("Annotated" as const), cause: tie("Cause") }), Cause: fc.oneof( tie("Empty"), tie("Fail"), tie("Die"), tie("Interrupt"), tie("Sequential"), - tie("Parallel") - ) as any as fastCheck_.Arbitrary> - })).Cause.map(causeDecode) + tie("Parallel"), + tie("Annotated") + ) as any as fastCheck_.Arbitrary> + })).Cause + +const causeArbitrary = ( + error: LazyArbitrary, + defect: LazyArbitrary +): LazyArbitrary> => +(fc) => causeEncodedArbitrary(error, defect)(fc).map(causeDecode) const causePretty = (error: pretty_.Pretty): pretty_.Pretty> => (cause) => { const f = (cause: cause_.Cause): string => { @@ -8399,6 +8419,8 @@ const causePretty = (error: pretty_.Pretty): pretty_.Pretty(cause: CauseEncoded): cause_.Cause { return cause_.sequential(causeDecode(cause.left), causeDecode(cause.right)) case "Parallel": return cause_.parallel(causeDecode(cause.left), causeDecode(cause.right)) + case "Annotated": + return cause_.annotated(causeDecode(cause.cause), context_.empty()) } } @@ -8486,6 +8510,8 @@ function causeEncode(cause: cause_.Cause): CauseEncoded { left: causeEncode(cause.left), right: causeEncode(cause.right) } + case "Annotated": + return causeEncode(cause.cause) } } @@ -8626,7 +8652,7 @@ const exitArbitrary = ( ): LazyArbitrary> => (fc) => fc.oneof( - fc.record({ _tag: fc.constant("Failure" as const), cause: causeArbitrary(error, defect)(fc) }), + fc.record({ _tag: fc.constant("Failure" as const), cause: causeEncodedArbitrary(error, defect)(fc) }), fc.record({ _tag: fc.constant("Success" as const), value: value(fc) }) ).map(exitDecode) diff --git a/packages/schema/test/Schema/Cause/Cause.test.ts b/packages/schema/test/Schema/Cause/Cause.test.ts index 639828e56a1..ae513efeaa3 100644 --- a/packages/schema/test/Schema/Cause/Cause.test.ts +++ b/packages/schema/test/Schema/Cause/Cause.test.ts @@ -78,7 +78,7 @@ describe("Cause", () => { `(CauseEncoded <-> Cause) └─ Encoded side transformation failure └─ CauseEncoded - └─ { readonly _tag: "Empty" | "Fail" | "Die" | "Interrupt" | "Sequential" | "Parallel" } + └─ { readonly _tag: "Empty" | "Fail" | "Die" | "Interrupt" | "Sequential" | "Parallel" | "Annotated" } └─ ["_tag"] └─ is missing` )