mirror of
https://github.com/Effect-TS/effect.git
synced 2026-12-06 03:59:09 +08:00
test(Config): consolidate provider composite cause regressions
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
import { assert, describe, it } from "@effect/vitest"
|
||||
import {
|
||||
ByteSize,
|
||||
Cause,
|
||||
Config,
|
||||
ConfigProvider,
|
||||
Duration,
|
||||
Effect,
|
||||
Exit,
|
||||
Option,
|
||||
pipe,
|
||||
Redacted,
|
||||
@@ -88,6 +90,53 @@ describe("Config", () => {
|
||||
}
|
||||
}))
|
||||
|
||||
it.effect("keeps provider finalizer defects alongside wrapped source errors", () =>
|
||||
Effect.gen(function*() {
|
||||
const sourceError = new ConfigProvider.SourceError({ message: "read failed" })
|
||||
const cleanup = new Error("cleanup failed")
|
||||
const provider = ConfigProvider.make(() => Effect.fail(sourceError).pipe(Effect.ensuring(Effect.die(cleanup))))
|
||||
const config = Config.String("value")
|
||||
const exit = yield* Effect.exit(config.parse(provider))
|
||||
|
||||
assert.deepStrictEqual(
|
||||
exit,
|
||||
Exit.failCause(Cause.combine(Cause.fail(new Config.ConfigError(sourceError)), Cause.die(cleanup)))
|
||||
)
|
||||
let recovered = false
|
||||
const fallbackExit = yield* Effect.exit(
|
||||
config.pipe(Config.orElse(() => {
|
||||
recovered = true
|
||||
return Config.succeed("fallback")
|
||||
})).parse(provider)
|
||||
)
|
||||
assert.strictEqual(recovered, false)
|
||||
assert.deepStrictEqual(fallbackExit, exit)
|
||||
}))
|
||||
|
||||
it.effect("preserves every defect in a provider cause", () =>
|
||||
Effect.gen(function*() {
|
||||
const first = new Error("first defect")
|
||||
const second = new Error("second defect")
|
||||
const cause = Cause.combine(Cause.die(first), Cause.die(second))
|
||||
const provider = ConfigProvider.make(() => Effect.failCause(cause))
|
||||
const exit = yield* Effect.exit(Config.String("value").parse(provider))
|
||||
|
||||
assert.deepStrictEqual(exit, Exit.failCause(cause))
|
||||
}))
|
||||
|
||||
it("keeps provider interruption reasons alongside wrapped source errors", async () => {
|
||||
const sourceError = new ConfigProvider.SourceError({ message: "read interrupted" })
|
||||
const provider = ConfigProvider.make(() =>
|
||||
Effect.failCause(Cause.combine(Cause.fail(sourceError), Cause.interrupt(123)))
|
||||
)
|
||||
const exit = await Effect.runPromiseExit(Config.String("value").parse(provider))
|
||||
|
||||
assert.deepStrictEqual(
|
||||
exit,
|
||||
Exit.failCause(Cause.combine(Cause.fail(new Config.ConfigError(sourceError)), Cause.interrupt(123)))
|
||||
)
|
||||
})
|
||||
|
||||
describe("constructors", () => {
|
||||
it("fail creates an always-failing config", async () => {
|
||||
await assertFailure(
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
import { assert, describe, it } from "@effect/vitest"
|
||||
import { Cause, Config, ConfigProvider, Effect, Exit } from "effect"
|
||||
|
||||
describe("Config", () => {
|
||||
// packages/effect/src/Config.ts:620 (Effect.orDie in loadCursor) and :839 (catchDefect rebuilding a
|
||||
// single Fail(ConfigError)). ConfigError only wraps the SourceError; independent finalizer defects must
|
||||
// be retained, as in Effect.test.ts "onExit preserves the original failure when the finalizer throws".
|
||||
it.effect("keeps a provider finalizer defect alongside the wrapped SourceError", () =>
|
||||
Effect.gen(function*() {
|
||||
const cleanup = new Error("cleanup failed")
|
||||
const provider = ConfigProvider.make(() =>
|
||||
Effect.fail(new ConfigProvider.SourceError({ message: "read failed" })).pipe(
|
||||
Effect.ensuring(Effect.die(cleanup))
|
||||
)
|
||||
)
|
||||
const exit = yield* Effect.exit(Config.String("A").parse(provider))
|
||||
|
||||
assert.isTrue(Exit.isFailure(exit))
|
||||
if (Exit.isFailure(exit)) {
|
||||
assert.deepStrictEqual(exit.cause.reasons.filter(Cause.isDieReason).map((r) => r.defect), [cleanup])
|
||||
}
|
||||
}))
|
||||
})
|
||||
Reference in New Issue
Block a user