@clayroach/effect 3.19.14-source-capture.6 → 3.19.14-source-capture.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/Utils.js +1 -1
- package/dist/cjs/Utils.js.map +1 -1
- package/dist/cjs/internal/clock.js +1 -1
- package/dist/cjs/internal/clock.js.map +1 -1
- package/dist/esm/Utils.js +1 -1
- package/dist/esm/Utils.js.map +1 -1
- package/dist/esm/internal/clock.js +1 -1
- package/dist/esm/internal/clock.js.map +1 -1
- package/package.json +1 -1
- package/src/Arbitrary.ts +0 -1101
- package/src/Array.ts +0 -3589
- package/src/BigDecimal.ts +0 -1349
- package/src/BigInt.ts +0 -643
- package/src/Boolean.ts +0 -287
- package/src/Brand.ts +0 -360
- package/src/Cache.ts +0 -281
- package/src/Cause.ts +0 -1555
- package/src/Channel.ts +0 -2355
- package/src/ChildExecutorDecision.ts +0 -146
- package/src/Chunk.ts +0 -1495
- package/src/Clock.ts +0 -111
- package/src/Config.ts +0 -542
- package/src/ConfigError.ts +0 -270
- package/src/ConfigProvider.ts +0 -333
- package/src/ConfigProviderPathPatch.ts +0 -100
- package/src/Console.ts +0 -226
- package/src/Context.ts +0 -585
- package/src/Cron.ts +0 -706
- package/src/Data.ts +0 -596
- package/src/DateTime.ts +0 -1686
- package/src/DefaultServices.ts +0 -34
- package/src/Deferred.ts +0 -301
- package/src/Differ.ts +0 -450
- package/src/Duration.ts +0 -1000
- package/src/Effect.ts +0 -14839
- package/src/Effectable.ts +0 -107
- package/src/Either.ts +0 -1040
- package/src/Encoding.ts +0 -195
- package/src/Equal.ts +0 -98
- package/src/Equivalence.ts +0 -235
- package/src/ExecutionPlan.ts +0 -308
- package/src/ExecutionStrategy.ts +0 -119
- package/src/Exit.ts +0 -467
- package/src/FastCheck.ts +0 -9
- package/src/Fiber.ts +0 -744
- package/src/FiberHandle.ts +0 -540
- package/src/FiberId.ts +0 -195
- package/src/FiberMap.ts +0 -656
- package/src/FiberRef.ts +0 -431
- package/src/FiberRefs.ts +0 -204
- package/src/FiberRefsPatch.ts +0 -105
- package/src/FiberSet.ts +0 -491
- package/src/FiberStatus.ts +0 -108
- package/src/Function.ts +0 -1222
- package/src/GlobalValue.ts +0 -53
- package/src/Graph.ts +0 -3732
- package/src/GroupBy.ts +0 -103
- package/src/HKT.ts +0 -45
- package/src/Hash.ts +0 -195
- package/src/HashMap.ts +0 -519
- package/src/HashRing.ts +0 -317
- package/src/HashSet.ts +0 -2346
- package/src/Inspectable.ts +0 -287
- package/src/Iterable.ts +0 -1119
- package/src/JSONSchema.ts +0 -1044
- package/src/KeyedPool.ts +0 -167
- package/src/Layer.ts +0 -1251
- package/src/LayerMap.ts +0 -436
- package/src/List.ts +0 -977
- package/src/LogLevel.ts +0 -285
- package/src/LogSpan.ts +0 -25
- package/src/Logger.ts +0 -702
- package/src/Mailbox.ts +0 -268
- package/src/ManagedRuntime.ts +0 -180
- package/src/Match.ts +0 -1477
- package/src/MergeDecision.ts +0 -95
- package/src/MergeState.ts +0 -172
- package/src/MergeStrategy.ts +0 -107
- package/src/Metric.ts +0 -780
- package/src/MetricBoundaries.ts +0 -69
- package/src/MetricHook.ts +0 -151
- package/src/MetricKey.ts +0 -224
- package/src/MetricKeyType.ts +0 -262
- package/src/MetricLabel.ts +0 -47
- package/src/MetricPair.ts +0 -71
- package/src/MetricPolling.ts +0 -148
- package/src/MetricRegistry.ts +0 -48
- package/src/MetricState.ts +0 -257
- package/src/Micro.ts +0 -4405
- package/src/ModuleVersion.ts +0 -18
- package/src/MutableHashMap.ts +0 -411
- package/src/MutableHashSet.ts +0 -706
- package/src/MutableList.ts +0 -297
- package/src/MutableQueue.ts +0 -227
- package/src/MutableRef.ts +0 -202
- package/src/NonEmptyIterable.ts +0 -32
- package/src/Number.ts +0 -1071
- package/src/Option.ts +0 -2170
- package/src/Order.ts +0 -373
- package/src/Ordering.ts +0 -111
- package/src/ParseResult.ts +0 -2031
- package/src/PartitionedSemaphore.ts +0 -200
- package/src/Pipeable.ts +0 -566
- package/src/Pool.ts +0 -204
- package/src/Predicate.ts +0 -1405
- package/src/Pretty.ts +0 -205
- package/src/PrimaryKey.ts +0 -23
- package/src/PubSub.ts +0 -182
- package/src/Queue.ts +0 -644
- package/src/Random.ts +0 -204
- package/src/RateLimiter.ts +0 -138
- package/src/RcMap.ts +0 -141
- package/src/RcRef.ts +0 -122
- package/src/Readable.ts +0 -93
- package/src/Record.ts +0 -1274
- package/src/RedBlackTree.ts +0 -421
- package/src/Redacted.ts +0 -144
- package/src/Ref.ts +0 -180
- package/src/RegExp.ts +0 -38
- package/src/Reloadable.ts +0 -127
- package/src/Request.ts +0 -347
- package/src/RequestBlock.ts +0 -118
- package/src/RequestResolver.ts +0 -366
- package/src/Resource.ts +0 -119
- package/src/Runtime.ts +0 -383
- package/src/RuntimeFlags.ts +0 -368
- package/src/RuntimeFlagsPatch.ts +0 -183
- package/src/STM.ts +0 -2045
- package/src/Schedule.ts +0 -2219
- package/src/ScheduleDecision.ts +0 -62
- package/src/ScheduleInterval.ts +0 -151
- package/src/ScheduleIntervals.ts +0 -122
- package/src/Scheduler.ts +0 -353
- package/src/Schema.ts +0 -10914
- package/src/SchemaAST.ts +0 -3043
- package/src/Scope.ts +0 -204
- package/src/ScopedCache.ts +0 -151
- package/src/ScopedRef.ts +0 -117
- package/src/Secret.ts +0 -88
- package/src/SingleProducerAsyncInput.ts +0 -67
- package/src/Sink.ts +0 -1461
- package/src/SortedMap.ts +0 -287
- package/src/SortedSet.ts +0 -390
- package/src/Stream.ts +0 -6468
- package/src/StreamEmit.ts +0 -136
- package/src/StreamHaltStrategy.ts +0 -123
- package/src/Streamable.ts +0 -45
- package/src/String.ts +0 -778
- package/src/Struct.ts +0 -243
- package/src/Subscribable.ts +0 -100
- package/src/SubscriptionRef.ts +0 -298
- package/src/Supervisor.ts +0 -240
- package/src/Symbol.ts +0 -29
- package/src/SynchronizedRef.ts +0 -270
- package/src/TArray.ts +0 -495
- package/src/TDeferred.ts +0 -100
- package/src/TMap.ts +0 -515
- package/src/TPriorityQueue.ts +0 -223
- package/src/TPubSub.ts +0 -200
- package/src/TQueue.ts +0 -432
- package/src/TRandom.ts +0 -129
- package/src/TReentrantLock.ts +0 -224
- package/src/TRef.ts +0 -178
- package/src/TSemaphore.ts +0 -129
- package/src/TSet.ts +0 -365
- package/src/TSubscriptionRef.ts +0 -192
- package/src/Take.ts +0 -258
- package/src/TestAnnotation.ts +0 -158
- package/src/TestAnnotationMap.ts +0 -119
- package/src/TestAnnotations.ts +0 -117
- package/src/TestClock.ts +0 -556
- package/src/TestConfig.ts +0 -47
- package/src/TestContext.ts +0 -36
- package/src/TestLive.ts +0 -53
- package/src/TestServices.ts +0 -390
- package/src/TestSized.ts +0 -55
- package/src/Tracer.ts +0 -198
- package/src/Trie.ts +0 -840
- package/src/Tuple.ts +0 -305
- package/src/Types.ts +0 -353
- package/src/Unify.ts +0 -113
- package/src/UpstreamPullRequest.ts +0 -117
- package/src/UpstreamPullStrategy.ts +0 -121
- package/src/Utils.ts +0 -809
- package/src/index.ts +0 -1561
- package/src/internal/array.ts +0 -8
- package/src/internal/blockedRequests.ts +0 -520
- package/src/internal/cache.ts +0 -733
- package/src/internal/cause.ts +0 -1050
- package/src/internal/channel/channelExecutor.ts +0 -1200
- package/src/internal/channel/channelState.ts +0 -134
- package/src/internal/channel/childExecutorDecision.ts +0 -96
- package/src/internal/channel/continuation.ts +0 -200
- package/src/internal/channel/mergeDecision.ts +0 -113
- package/src/internal/channel/mergeState.ts +0 -120
- package/src/internal/channel/mergeStrategy.ts +0 -72
- package/src/internal/channel/singleProducerAsyncInput.ts +0 -259
- package/src/internal/channel/subexecutor.ts +0 -229
- package/src/internal/channel/upstreamPullRequest.ts +0 -84
- package/src/internal/channel/upstreamPullStrategy.ts +0 -87
- package/src/internal/channel.ts +0 -2603
- package/src/internal/clock.ts +0 -95
- package/src/internal/completedRequestMap.ts +0 -9
- package/src/internal/concurrency.ts +0 -54
- package/src/internal/config.ts +0 -716
- package/src/internal/configError.ts +0 -304
- package/src/internal/configProvider/pathPatch.ts +0 -97
- package/src/internal/configProvider.ts +0 -799
- package/src/internal/console.ts +0 -153
- package/src/internal/context.ts +0 -337
- package/src/internal/core-effect.ts +0 -2293
- package/src/internal/core-stream.ts +0 -998
- package/src/internal/core.ts +0 -3273
- package/src/internal/data.ts +0 -36
- package/src/internal/dataSource.ts +0 -327
- package/src/internal/dateTime.ts +0 -1277
- package/src/internal/defaultServices/console.ts +0 -100
- package/src/internal/defaultServices.ts +0 -163
- package/src/internal/deferred.ts +0 -46
- package/src/internal/differ/chunkPatch.ts +0 -211
- package/src/internal/differ/contextPatch.ts +0 -232
- package/src/internal/differ/hashMapPatch.ts +0 -220
- package/src/internal/differ/hashSetPatch.ts +0 -176
- package/src/internal/differ/orPatch.ts +0 -311
- package/src/internal/differ/readonlyArrayPatch.ts +0 -210
- package/src/internal/differ.ts +0 -200
- package/src/internal/doNotation.ts +0 -80
- package/src/internal/effect/circular.ts +0 -905
- package/src/internal/effectable.ts +0 -131
- package/src/internal/either.ts +0 -110
- package/src/internal/encoding/base64.ts +0 -286
- package/src/internal/encoding/base64Url.ts +0 -29
- package/src/internal/encoding/common.ts +0 -51
- package/src/internal/encoding/hex.ts +0 -315
- package/src/internal/errors.ts +0 -7
- package/src/internal/executionPlan.ts +0 -114
- package/src/internal/executionStrategy.ts +0 -74
- package/src/internal/fiber.ts +0 -388
- package/src/internal/fiberId.ts +0 -267
- package/src/internal/fiberMessage.ts +0 -82
- package/src/internal/fiberRefs/patch.ts +0 -144
- package/src/internal/fiberRefs.ts +0 -297
- package/src/internal/fiberRuntime.ts +0 -3915
- package/src/internal/fiberScope.ts +0 -71
- package/src/internal/fiberStatus.ts +0 -119
- package/src/internal/groupBy.ts +0 -530
- package/src/internal/hashMap/array.ts +0 -49
- package/src/internal/hashMap/bitwise.ts +0 -32
- package/src/internal/hashMap/config.ts +0 -14
- package/src/internal/hashMap/keySet.ts +0 -8
- package/src/internal/hashMap/node.ts +0 -391
- package/src/internal/hashMap.ts +0 -586
- package/src/internal/hashSet.ts +0 -323
- package/src/internal/keyedPool.ts +0 -244
- package/src/internal/layer/circular.ts +0 -228
- package/src/internal/layer.ts +0 -1487
- package/src/internal/logSpan.ts +0 -20
- package/src/internal/logger-circular.ts +0 -24
- package/src/internal/logger.ts +0 -485
- package/src/internal/mailbox.ts +0 -561
- package/src/internal/managedRuntime/circular.ts +0 -6
- package/src/internal/managedRuntime.ts +0 -134
- package/src/internal/matcher.ts +0 -652
- package/src/internal/metric/boundaries.ts +0 -75
- package/src/internal/metric/hook.ts +0 -483
- package/src/internal/metric/key.ts +0 -167
- package/src/internal/metric/keyType.ts +0 -238
- package/src/internal/metric/label.ts +0 -41
- package/src/internal/metric/pair.ts +0 -48
- package/src/internal/metric/polling.ts +0 -149
- package/src/internal/metric/registry.ts +0 -187
- package/src/internal/metric/state.ts +0 -290
- package/src/internal/metric.ts +0 -577
- package/src/internal/opCodes/cause.ts +0 -35
- package/src/internal/opCodes/channel.ts +0 -83
- package/src/internal/opCodes/channelChildExecutorDecision.ts +0 -17
- package/src/internal/opCodes/channelMergeDecision.ts +0 -11
- package/src/internal/opCodes/channelMergeState.ts +0 -17
- package/src/internal/opCodes/channelMergeStrategy.ts +0 -11
- package/src/internal/opCodes/channelState.ts +0 -23
- package/src/internal/opCodes/channelUpstreamPullRequest.ts +0 -11
- package/src/internal/opCodes/channelUpstreamPullStrategy.ts +0 -11
- package/src/internal/opCodes/config.ts +0 -65
- package/src/internal/opCodes/configError.ts +0 -35
- package/src/internal/opCodes/continuation.ts +0 -11
- package/src/internal/opCodes/deferred.ts +0 -11
- package/src/internal/opCodes/effect.ts +0 -89
- package/src/internal/opCodes/layer.ts +0 -59
- package/src/internal/opCodes/streamHaltStrategy.ts +0 -23
- package/src/internal/option.ts +0 -80
- package/src/internal/pool.ts +0 -432
- package/src/internal/pubsub.ts +0 -1762
- package/src/internal/query.ts +0 -204
- package/src/internal/queue.ts +0 -766
- package/src/internal/random.ts +0 -161
- package/src/internal/rateLimiter.ts +0 -93
- package/src/internal/rcMap.ts +0 -285
- package/src/internal/rcRef.ts +0 -192
- package/src/internal/redBlackTree/iterator.ts +0 -200
- package/src/internal/redBlackTree/node.ts +0 -68
- package/src/internal/redBlackTree.ts +0 -1245
- package/src/internal/redacted.ts +0 -73
- package/src/internal/ref.ts +0 -171
- package/src/internal/reloadable.ts +0 -140
- package/src/internal/request.ts +0 -177
- package/src/internal/resource.ts +0 -76
- package/src/internal/ringBuffer.ts +0 -68
- package/src/internal/runtime.ts +0 -558
- package/src/internal/runtimeFlags.ts +0 -188
- package/src/internal/runtimeFlagsPatch.ts +0 -103
- package/src/internal/schedule/decision.ts +0 -47
- package/src/internal/schedule/interval.ts +0 -101
- package/src/internal/schedule/intervals.ts +0 -180
- package/src/internal/schedule.ts +0 -2199
- package/src/internal/schema/errors.ts +0 -191
- package/src/internal/schema/schemaId.ts +0 -106
- package/src/internal/schema/util.ts +0 -50
- package/src/internal/scopedCache.ts +0 -644
- package/src/internal/scopedRef.ts +0 -118
- package/src/internal/secret.ts +0 -89
- package/src/internal/singleShotGen.ts +0 -35
- package/src/internal/sink.ts +0 -2120
- package/src/internal/stack.ts +0 -10
- package/src/internal/stm/core.ts +0 -817
- package/src/internal/stm/entry.ts +0 -59
- package/src/internal/stm/journal.ts +0 -123
- package/src/internal/stm/opCodes/stm.ts +0 -71
- package/src/internal/stm/opCodes/stmState.ts +0 -17
- package/src/internal/stm/opCodes/strategy.ts +0 -17
- package/src/internal/stm/opCodes/tExit.ts +0 -29
- package/src/internal/stm/opCodes/tryCommit.ts +0 -11
- package/src/internal/stm/stm.ts +0 -1453
- package/src/internal/stm/stmState.ts +0 -136
- package/src/internal/stm/tArray.ts +0 -550
- package/src/internal/stm/tDeferred.ts +0 -81
- package/src/internal/stm/tExit.ts +0 -190
- package/src/internal/stm/tMap.ts +0 -824
- package/src/internal/stm/tPriorityQueue.ts +0 -267
- package/src/internal/stm/tPubSub.ts +0 -551
- package/src/internal/stm/tQueue.ts +0 -393
- package/src/internal/stm/tRandom.ts +0 -140
- package/src/internal/stm/tReentrantLock.ts +0 -352
- package/src/internal/stm/tRef.ts +0 -195
- package/src/internal/stm/tSemaphore.ts +0 -113
- package/src/internal/stm/tSet.ts +0 -259
- package/src/internal/stm/tSubscriptionRef.ts +0 -286
- package/src/internal/stm/tryCommit.ts +0 -34
- package/src/internal/stm/txnId.ts +0 -14
- package/src/internal/stm/versioned.ts +0 -4
- package/src/internal/stream/debounceState.ts +0 -57
- package/src/internal/stream/emit.ts +0 -123
- package/src/internal/stream/haltStrategy.ts +0 -94
- package/src/internal/stream/handoff.ts +0 -187
- package/src/internal/stream/handoffSignal.ts +0 -59
- package/src/internal/stream/pull.ts +0 -34
- package/src/internal/stream/sinkEndReason.ts +0 -30
- package/src/internal/stream/zipAllState.ts +0 -88
- package/src/internal/stream/zipChunksState.ts +0 -56
- package/src/internal/stream.ts +0 -8801
- package/src/internal/string-utils.ts +0 -107
- package/src/internal/subscriptionRef.ts +0 -138
- package/src/internal/supervisor/patch.ts +0 -190
- package/src/internal/supervisor.ts +0 -303
- package/src/internal/synchronizedRef.ts +0 -114
- package/src/internal/take.ts +0 -199
- package/src/internal/testing/sleep.ts +0 -27
- package/src/internal/testing/suspendedWarningData.ts +0 -85
- package/src/internal/testing/warningData.ts +0 -94
- package/src/internal/tracer.ts +0 -293
- package/src/internal/trie.ts +0 -722
- package/src/internal/version.ts +0 -7
package/src/internal/cause.ts
DELETED
|
@@ -1,1050 +0,0 @@
|
|
|
1
|
-
import * as Arr from "../Array.js"
|
|
2
|
-
import type * as Cause from "../Cause.js"
|
|
3
|
-
import * as Chunk from "../Chunk.js"
|
|
4
|
-
import * as Either from "../Either.js"
|
|
5
|
-
import * as Equal from "../Equal.js"
|
|
6
|
-
import type * as FiberId from "../FiberId.js"
|
|
7
|
-
import { constFalse, constTrue, dual, identity, pipe } from "../Function.js"
|
|
8
|
-
import { globalValue } from "../GlobalValue.js"
|
|
9
|
-
import * as Hash from "../Hash.js"
|
|
10
|
-
import * as HashSet from "../HashSet.js"
|
|
11
|
-
import { NodeInspectSymbol, stringifyCircular, toJSON } from "../Inspectable.js"
|
|
12
|
-
import * as Option from "../Option.js"
|
|
13
|
-
import { pipeArguments } from "../Pipeable.js"
|
|
14
|
-
import type { Predicate, Refinement } from "../Predicate.js"
|
|
15
|
-
import { hasProperty, isFunction } from "../Predicate.js"
|
|
16
|
-
import type { AnySpan, Span } from "../Tracer.js"
|
|
17
|
-
import type { NoInfer } from "../Types.js"
|
|
18
|
-
import { getBugErrorMessage } from "./errors.js"
|
|
19
|
-
import * as OpCodes from "./opCodes/cause.js"
|
|
20
|
-
|
|
21
|
-
// -----------------------------------------------------------------------------
|
|
22
|
-
// Models
|
|
23
|
-
// -----------------------------------------------------------------------------
|
|
24
|
-
|
|
25
|
-
/** @internal */
|
|
26
|
-
const CauseSymbolKey = "effect/Cause"
|
|
27
|
-
|
|
28
|
-
/** @internal */
|
|
29
|
-
export const CauseTypeId: Cause.CauseTypeId = Symbol.for(
|
|
30
|
-
CauseSymbolKey
|
|
31
|
-
) as Cause.CauseTypeId
|
|
32
|
-
|
|
33
|
-
const variance = {
|
|
34
|
-
/* c8 ignore next */
|
|
35
|
-
_E: (_: never) => _
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/** @internal */
|
|
39
|
-
const proto = {
|
|
40
|
-
[CauseTypeId]: variance,
|
|
41
|
-
[Hash.symbol](this: Cause.Cause<any>): number {
|
|
42
|
-
return pipe(
|
|
43
|
-
Hash.hash(CauseSymbolKey),
|
|
44
|
-
Hash.combine(Hash.hash(flattenCause(this))),
|
|
45
|
-
Hash.cached(this)
|
|
46
|
-
)
|
|
47
|
-
},
|
|
48
|
-
[Equal.symbol](this: Cause.Cause<any>, that: unknown): boolean {
|
|
49
|
-
return isCause(that) && causeEquals(this, that)
|
|
50
|
-
},
|
|
51
|
-
pipe() {
|
|
52
|
-
return pipeArguments(this, arguments)
|
|
53
|
-
},
|
|
54
|
-
toJSON<E>(this: Cause.Cause<E>) {
|
|
55
|
-
switch (this._tag) {
|
|
56
|
-
case "Empty":
|
|
57
|
-
return { _id: "Cause", _tag: this._tag }
|
|
58
|
-
case "Die":
|
|
59
|
-
return { _id: "Cause", _tag: this._tag, defect: toJSON(this.defect) }
|
|
60
|
-
case "Interrupt":
|
|
61
|
-
return { _id: "Cause", _tag: this._tag, fiberId: this.fiberId.toJSON() }
|
|
62
|
-
case "Fail":
|
|
63
|
-
return { _id: "Cause", _tag: this._tag, failure: toJSON(this.error) }
|
|
64
|
-
case "Sequential":
|
|
65
|
-
case "Parallel":
|
|
66
|
-
return { _id: "Cause", _tag: this._tag, left: toJSON(this.left), right: toJSON(this.right) }
|
|
67
|
-
}
|
|
68
|
-
},
|
|
69
|
-
toString<E>(this: Cause.Cause<E>) {
|
|
70
|
-
return pretty(this)
|
|
71
|
-
},
|
|
72
|
-
[NodeInspectSymbol]<E>(this: Cause.Cause<E>) {
|
|
73
|
-
return this.toJSON()
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
// -----------------------------------------------------------------------------
|
|
78
|
-
// Constructors
|
|
79
|
-
// -----------------------------------------------------------------------------
|
|
80
|
-
|
|
81
|
-
/** @internal */
|
|
82
|
-
export const empty: Cause.Cause<never> = (() => {
|
|
83
|
-
const o = Object.create(proto)
|
|
84
|
-
o._tag = OpCodes.OP_EMPTY
|
|
85
|
-
return o
|
|
86
|
-
})()
|
|
87
|
-
|
|
88
|
-
/** @internal */
|
|
89
|
-
export const fail = <E>(error: E): Cause.Cause<E> => {
|
|
90
|
-
const o = Object.create(proto)
|
|
91
|
-
o._tag = OpCodes.OP_FAIL
|
|
92
|
-
o.error = error
|
|
93
|
-
return o
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/** @internal */
|
|
97
|
-
export const die = (defect: unknown): Cause.Cause<never> => {
|
|
98
|
-
const o = Object.create(proto)
|
|
99
|
-
o._tag = OpCodes.OP_DIE
|
|
100
|
-
o.defect = defect
|
|
101
|
-
return o
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/** @internal */
|
|
105
|
-
export const interrupt = (fiberId: FiberId.FiberId): Cause.Cause<never> => {
|
|
106
|
-
const o = Object.create(proto)
|
|
107
|
-
o._tag = OpCodes.OP_INTERRUPT
|
|
108
|
-
o.fiberId = fiberId
|
|
109
|
-
return o
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/** @internal */
|
|
113
|
-
export const parallel = <E, E2>(left: Cause.Cause<E>, right: Cause.Cause<E2>): Cause.Cause<E | E2> => {
|
|
114
|
-
const o = Object.create(proto)
|
|
115
|
-
o._tag = OpCodes.OP_PARALLEL
|
|
116
|
-
o.left = left
|
|
117
|
-
o.right = right
|
|
118
|
-
return o
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
/** @internal */
|
|
122
|
-
export const sequential = <E, E2>(left: Cause.Cause<E>, right: Cause.Cause<E2>): Cause.Cause<E | E2> => {
|
|
123
|
-
const o = Object.create(proto)
|
|
124
|
-
o._tag = OpCodes.OP_SEQUENTIAL
|
|
125
|
-
o.left = left
|
|
126
|
-
o.right = right
|
|
127
|
-
return o
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
// -----------------------------------------------------------------------------
|
|
131
|
-
// Refinements
|
|
132
|
-
// -----------------------------------------------------------------------------
|
|
133
|
-
|
|
134
|
-
/** @internal */
|
|
135
|
-
export const isCause = (u: unknown): u is Cause.Cause<unknown> => hasProperty(u, CauseTypeId)
|
|
136
|
-
|
|
137
|
-
/** @internal */
|
|
138
|
-
export const isEmptyType = <E>(self: Cause.Cause<E>): self is Cause.Empty => self._tag === OpCodes.OP_EMPTY
|
|
139
|
-
|
|
140
|
-
/** @internal */
|
|
141
|
-
export const isFailType = <E>(self: Cause.Cause<E>): self is Cause.Fail<E> => self._tag === OpCodes.OP_FAIL
|
|
142
|
-
|
|
143
|
-
/** @internal */
|
|
144
|
-
export const isDieType = <E>(self: Cause.Cause<E>): self is Cause.Die => self._tag === OpCodes.OP_DIE
|
|
145
|
-
|
|
146
|
-
/** @internal */
|
|
147
|
-
export const isInterruptType = <E>(self: Cause.Cause<E>): self is Cause.Interrupt => self._tag === OpCodes.OP_INTERRUPT
|
|
148
|
-
|
|
149
|
-
/** @internal */
|
|
150
|
-
export const isSequentialType = <E>(self: Cause.Cause<E>): self is Cause.Sequential<E> =>
|
|
151
|
-
self._tag === OpCodes.OP_SEQUENTIAL
|
|
152
|
-
|
|
153
|
-
/** @internal */
|
|
154
|
-
export const isParallelType = <E>(self: Cause.Cause<E>): self is Cause.Parallel<E> => self._tag === OpCodes.OP_PARALLEL
|
|
155
|
-
|
|
156
|
-
// -----------------------------------------------------------------------------
|
|
157
|
-
// Getters
|
|
158
|
-
// -----------------------------------------------------------------------------
|
|
159
|
-
|
|
160
|
-
/** @internal */
|
|
161
|
-
export const size = <E>(self: Cause.Cause<E>): number => reduceWithContext(self, void 0, SizeCauseReducer)
|
|
162
|
-
|
|
163
|
-
/** @internal */
|
|
164
|
-
export const isEmpty = <E>(self: Cause.Cause<E>): boolean => {
|
|
165
|
-
if (self._tag === OpCodes.OP_EMPTY) {
|
|
166
|
-
return true
|
|
167
|
-
}
|
|
168
|
-
return reduce(self, true, (acc, cause) => {
|
|
169
|
-
switch (cause._tag) {
|
|
170
|
-
case OpCodes.OP_EMPTY: {
|
|
171
|
-
return Option.some(acc)
|
|
172
|
-
}
|
|
173
|
-
case OpCodes.OP_DIE:
|
|
174
|
-
case OpCodes.OP_FAIL:
|
|
175
|
-
case OpCodes.OP_INTERRUPT: {
|
|
176
|
-
return Option.some(false)
|
|
177
|
-
}
|
|
178
|
-
default: {
|
|
179
|
-
return Option.none()
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
})
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
/** @internal */
|
|
186
|
-
export const isFailure = <E>(self: Cause.Cause<E>): boolean => Option.isSome(failureOption(self))
|
|
187
|
-
|
|
188
|
-
/** @internal */
|
|
189
|
-
export const isDie = <E>(self: Cause.Cause<E>): boolean => Option.isSome(dieOption(self))
|
|
190
|
-
|
|
191
|
-
/** @internal */
|
|
192
|
-
export const isInterrupted = <E>(self: Cause.Cause<E>): boolean => Option.isSome(interruptOption(self))
|
|
193
|
-
|
|
194
|
-
/** @internal */
|
|
195
|
-
export const isInterruptedOnly = <E>(self: Cause.Cause<E>): boolean =>
|
|
196
|
-
reduceWithContext(undefined, IsInterruptedOnlyCauseReducer)(self)
|
|
197
|
-
|
|
198
|
-
/** @internal */
|
|
199
|
-
export const failures = <E>(self: Cause.Cause<E>): Chunk.Chunk<E> =>
|
|
200
|
-
Chunk.reverse(
|
|
201
|
-
reduce<Chunk.Chunk<E>, E>(
|
|
202
|
-
self,
|
|
203
|
-
Chunk.empty<E>(),
|
|
204
|
-
(list, cause) =>
|
|
205
|
-
cause._tag === OpCodes.OP_FAIL ?
|
|
206
|
-
Option.some(pipe(list, Chunk.prepend(cause.error))) :
|
|
207
|
-
Option.none()
|
|
208
|
-
)
|
|
209
|
-
)
|
|
210
|
-
|
|
211
|
-
/** @internal */
|
|
212
|
-
export const defects = <E>(self: Cause.Cause<E>): Chunk.Chunk<unknown> =>
|
|
213
|
-
Chunk.reverse(
|
|
214
|
-
reduce<Chunk.Chunk<unknown>, E>(
|
|
215
|
-
self,
|
|
216
|
-
Chunk.empty<unknown>(),
|
|
217
|
-
(list, cause) =>
|
|
218
|
-
cause._tag === OpCodes.OP_DIE ?
|
|
219
|
-
Option.some(pipe(list, Chunk.prepend(cause.defect))) :
|
|
220
|
-
Option.none()
|
|
221
|
-
)
|
|
222
|
-
)
|
|
223
|
-
|
|
224
|
-
/** @internal */
|
|
225
|
-
export const interruptors = <E>(self: Cause.Cause<E>): HashSet.HashSet<FiberId.FiberId> =>
|
|
226
|
-
reduce(self, HashSet.empty<FiberId.FiberId>(), (set, cause) =>
|
|
227
|
-
cause._tag === OpCodes.OP_INTERRUPT ?
|
|
228
|
-
Option.some(pipe(set, HashSet.add(cause.fiberId))) :
|
|
229
|
-
Option.none())
|
|
230
|
-
|
|
231
|
-
/** @internal */
|
|
232
|
-
export const failureOption = <E>(self: Cause.Cause<E>): Option.Option<E> =>
|
|
233
|
-
find<E, E>(self, (cause) =>
|
|
234
|
-
cause._tag === OpCodes.OP_FAIL ?
|
|
235
|
-
Option.some(cause.error) :
|
|
236
|
-
Option.none())
|
|
237
|
-
|
|
238
|
-
/** @internal */
|
|
239
|
-
export const failureOrCause = <E>(self: Cause.Cause<E>): Either.Either<Cause.Cause<never>, E> => {
|
|
240
|
-
const option = failureOption(self)
|
|
241
|
-
switch (option._tag) {
|
|
242
|
-
case "None": {
|
|
243
|
-
// no `E` inside this `Cause`, so it can be safely cast to `never`
|
|
244
|
-
return Either.right(self as Cause.Cause<never>)
|
|
245
|
-
}
|
|
246
|
-
case "Some": {
|
|
247
|
-
return Either.left(option.value)
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
/** @internal */
|
|
253
|
-
export const dieOption = <E>(self: Cause.Cause<E>): Option.Option<unknown> =>
|
|
254
|
-
find(self, (cause) =>
|
|
255
|
-
cause._tag === OpCodes.OP_DIE ?
|
|
256
|
-
Option.some(cause.defect) :
|
|
257
|
-
Option.none())
|
|
258
|
-
|
|
259
|
-
/** @internal */
|
|
260
|
-
export const flipCauseOption = <E>(self: Cause.Cause<Option.Option<E>>): Option.Option<Cause.Cause<E>> =>
|
|
261
|
-
match(self, {
|
|
262
|
-
onEmpty: Option.some<Cause.Cause<E>>(empty),
|
|
263
|
-
onFail: Option.map(fail),
|
|
264
|
-
onDie: (defect) => Option.some(die(defect)),
|
|
265
|
-
onInterrupt: (fiberId) => Option.some(interrupt(fiberId)),
|
|
266
|
-
onSequential: Option.mergeWith(sequential),
|
|
267
|
-
onParallel: Option.mergeWith(parallel)
|
|
268
|
-
})
|
|
269
|
-
|
|
270
|
-
/** @internal */
|
|
271
|
-
export const interruptOption = <E>(self: Cause.Cause<E>): Option.Option<FiberId.FiberId> =>
|
|
272
|
-
find(self, (cause) =>
|
|
273
|
-
cause._tag === OpCodes.OP_INTERRUPT ?
|
|
274
|
-
Option.some(cause.fiberId) :
|
|
275
|
-
Option.none())
|
|
276
|
-
|
|
277
|
-
/** @internal */
|
|
278
|
-
export const keepDefects = <E>(self: Cause.Cause<E>): Option.Option<Cause.Cause<never>> =>
|
|
279
|
-
match(self, {
|
|
280
|
-
onEmpty: Option.none(),
|
|
281
|
-
onFail: () => Option.none(),
|
|
282
|
-
onDie: (defect) => Option.some(die(defect)),
|
|
283
|
-
onInterrupt: () => Option.none(),
|
|
284
|
-
onSequential: Option.mergeWith(sequential),
|
|
285
|
-
onParallel: Option.mergeWith(parallel)
|
|
286
|
-
})
|
|
287
|
-
|
|
288
|
-
/** @internal */
|
|
289
|
-
export const keepDefectsAndElectFailures = <E>(self: Cause.Cause<E>): Option.Option<Cause.Cause<never>> =>
|
|
290
|
-
match(self, {
|
|
291
|
-
onEmpty: Option.none(),
|
|
292
|
-
onFail: (failure) => Option.some(die(failure)),
|
|
293
|
-
onDie: (defect) => Option.some(die(defect)),
|
|
294
|
-
onInterrupt: () => Option.none(),
|
|
295
|
-
onSequential: Option.mergeWith(sequential),
|
|
296
|
-
onParallel: Option.mergeWith(parallel)
|
|
297
|
-
})
|
|
298
|
-
|
|
299
|
-
/** @internal */
|
|
300
|
-
export const linearize = <E>(self: Cause.Cause<E>): HashSet.HashSet<Cause.Cause<E>> =>
|
|
301
|
-
match(self, {
|
|
302
|
-
onEmpty: HashSet.empty(),
|
|
303
|
-
onFail: (error) => HashSet.make(fail(error)),
|
|
304
|
-
onDie: (defect) => HashSet.make(die(defect)),
|
|
305
|
-
onInterrupt: (fiberId) => HashSet.make(interrupt(fiberId)),
|
|
306
|
-
onSequential: (leftSet, rightSet) =>
|
|
307
|
-
HashSet.flatMap(leftSet, (leftCause) => HashSet.map(rightSet, (rightCause) => sequential(leftCause, rightCause))),
|
|
308
|
-
onParallel: (leftSet, rightSet) =>
|
|
309
|
-
HashSet.flatMap(leftSet, (leftCause) => HashSet.map(rightSet, (rightCause) => parallel(leftCause, rightCause)))
|
|
310
|
-
})
|
|
311
|
-
|
|
312
|
-
/** @internal */
|
|
313
|
-
export const stripFailures = <E>(self: Cause.Cause<E>): Cause.Cause<never> =>
|
|
314
|
-
match(self, {
|
|
315
|
-
onEmpty: empty,
|
|
316
|
-
onFail: () => empty,
|
|
317
|
-
onDie: die,
|
|
318
|
-
onInterrupt: interrupt,
|
|
319
|
-
onSequential: sequential,
|
|
320
|
-
onParallel: parallel
|
|
321
|
-
})
|
|
322
|
-
|
|
323
|
-
/** @internal */
|
|
324
|
-
export const electFailures = <E>(self: Cause.Cause<E>): Cause.Cause<never> =>
|
|
325
|
-
match(self, {
|
|
326
|
-
onEmpty: empty,
|
|
327
|
-
onFail: die,
|
|
328
|
-
onDie: die,
|
|
329
|
-
onInterrupt: interrupt,
|
|
330
|
-
onSequential: sequential,
|
|
331
|
-
onParallel: parallel
|
|
332
|
-
})
|
|
333
|
-
|
|
334
|
-
/** @internal */
|
|
335
|
-
export const stripSomeDefects = dual<
|
|
336
|
-
(pf: (defect: unknown) => Option.Option<unknown>) => <E>(self: Cause.Cause<E>) => Option.Option<Cause.Cause<E>>,
|
|
337
|
-
<E>(self: Cause.Cause<E>, pf: (defect: unknown) => Option.Option<unknown>) => Option.Option<Cause.Cause<E>>
|
|
338
|
-
>(
|
|
339
|
-
2,
|
|
340
|
-
<E>(self: Cause.Cause<E>, pf: (defect: unknown) => Option.Option<unknown>): Option.Option<Cause.Cause<E>> =>
|
|
341
|
-
match(self, {
|
|
342
|
-
onEmpty: Option.some<Cause.Cause<E>>(empty),
|
|
343
|
-
onFail: (error) => Option.some(fail(error)),
|
|
344
|
-
onDie: (defect) => {
|
|
345
|
-
const option = pf(defect)
|
|
346
|
-
return Option.isSome(option) ? Option.none() : Option.some(die(defect))
|
|
347
|
-
},
|
|
348
|
-
onInterrupt: (fiberId) => Option.some(interrupt(fiberId)),
|
|
349
|
-
onSequential: Option.mergeWith(sequential),
|
|
350
|
-
onParallel: Option.mergeWith(parallel)
|
|
351
|
-
})
|
|
352
|
-
)
|
|
353
|
-
|
|
354
|
-
// -----------------------------------------------------------------------------
|
|
355
|
-
// Mapping
|
|
356
|
-
// -----------------------------------------------------------------------------
|
|
357
|
-
|
|
358
|
-
/** @internal */
|
|
359
|
-
export const as = dual<
|
|
360
|
-
<E2>(error: E2) => <E>(self: Cause.Cause<E>) => Cause.Cause<E2>,
|
|
361
|
-
<E, E2>(self: Cause.Cause<E>, error: E2) => Cause.Cause<E2>
|
|
362
|
-
>(2, (self, error) => map(self, () => error))
|
|
363
|
-
|
|
364
|
-
/** @internal */
|
|
365
|
-
export const map = dual<
|
|
366
|
-
<E, E2>(f: (e: E) => E2) => (self: Cause.Cause<E>) => Cause.Cause<E2>,
|
|
367
|
-
<E, E2>(self: Cause.Cause<E>, f: (e: E) => E2) => Cause.Cause<E2>
|
|
368
|
-
>(2, (self, f) => flatMap(self, (e) => fail(f(e))))
|
|
369
|
-
|
|
370
|
-
// -----------------------------------------------------------------------------
|
|
371
|
-
// Sequencing
|
|
372
|
-
// -----------------------------------------------------------------------------
|
|
373
|
-
|
|
374
|
-
/** @internal */
|
|
375
|
-
export const flatMap = dual<
|
|
376
|
-
<E, E2>(f: (e: E) => Cause.Cause<E2>) => (self: Cause.Cause<E>) => Cause.Cause<E2>,
|
|
377
|
-
<E, E2>(self: Cause.Cause<E>, f: (e: E) => Cause.Cause<E2>) => Cause.Cause<E2>
|
|
378
|
-
>(2, (self, f) =>
|
|
379
|
-
match(self, {
|
|
380
|
-
onEmpty: empty,
|
|
381
|
-
onFail: (error) => f(error),
|
|
382
|
-
onDie: (defect) => die(defect),
|
|
383
|
-
onInterrupt: (fiberId) => interrupt(fiberId),
|
|
384
|
-
onSequential: (left, right) => sequential(left, right),
|
|
385
|
-
onParallel: (left, right) => parallel(left, right)
|
|
386
|
-
}))
|
|
387
|
-
|
|
388
|
-
/** @internal */
|
|
389
|
-
export const flatten = <E>(self: Cause.Cause<Cause.Cause<E>>): Cause.Cause<E> => flatMap(self, identity)
|
|
390
|
-
|
|
391
|
-
/** @internal */
|
|
392
|
-
export const andThen: {
|
|
393
|
-
<E, E2>(f: (e: E) => Cause.Cause<E2>): (self: Cause.Cause<E>) => Cause.Cause<E2>
|
|
394
|
-
<E2>(f: Cause.Cause<E2>): <E>(self: Cause.Cause<E>) => Cause.Cause<E2>
|
|
395
|
-
<E, E2>(self: Cause.Cause<E>, f: (e: E) => Cause.Cause<E2>): Cause.Cause<E2>
|
|
396
|
-
<E, E2>(self: Cause.Cause<E>, f: Cause.Cause<E2>): Cause.Cause<E2>
|
|
397
|
-
} = dual(
|
|
398
|
-
2,
|
|
399
|
-
<E, E2>(self: Cause.Cause<E>, f: ((e: E) => Cause.Cause<E2>) | Cause.Cause<E2>): Cause.Cause<E2> =>
|
|
400
|
-
isFunction(f) ? flatMap(self, f) : flatMap(self, () => f)
|
|
401
|
-
)
|
|
402
|
-
|
|
403
|
-
// -----------------------------------------------------------------------------
|
|
404
|
-
// Equality
|
|
405
|
-
// -----------------------------------------------------------------------------
|
|
406
|
-
|
|
407
|
-
/** @internal */
|
|
408
|
-
export const contains = dual<
|
|
409
|
-
<E2>(that: Cause.Cause<E2>) => <E>(self: Cause.Cause<E>) => boolean,
|
|
410
|
-
<E, E2>(self: Cause.Cause<E>, that: Cause.Cause<E2>) => boolean
|
|
411
|
-
>(2, (self, that) => {
|
|
412
|
-
if (that._tag === OpCodes.OP_EMPTY || self === that) {
|
|
413
|
-
return true
|
|
414
|
-
}
|
|
415
|
-
return reduce(self, false, (accumulator, cause) => {
|
|
416
|
-
return Option.some(accumulator || causeEquals(cause, that))
|
|
417
|
-
})
|
|
418
|
-
})
|
|
419
|
-
|
|
420
|
-
/** @internal */
|
|
421
|
-
const causeEquals = (left: Cause.Cause<unknown>, right: Cause.Cause<unknown>): boolean => {
|
|
422
|
-
let leftStack: Chunk.Chunk<Cause.Cause<unknown>> = Chunk.of(left)
|
|
423
|
-
let rightStack: Chunk.Chunk<Cause.Cause<unknown>> = Chunk.of(right)
|
|
424
|
-
while (Chunk.isNonEmpty(leftStack) && Chunk.isNonEmpty(rightStack)) {
|
|
425
|
-
const [leftParallel, leftSequential] = pipe(
|
|
426
|
-
Chunk.headNonEmpty(leftStack),
|
|
427
|
-
reduce(
|
|
428
|
-
[HashSet.empty<unknown>(), Chunk.empty<Cause.Cause<unknown>>()] as const,
|
|
429
|
-
([parallel, sequential], cause) => {
|
|
430
|
-
const [par, seq] = evaluateCause(cause)
|
|
431
|
-
return Option.some(
|
|
432
|
-
[
|
|
433
|
-
pipe(parallel, HashSet.union(par)),
|
|
434
|
-
pipe(sequential, Chunk.appendAll(seq))
|
|
435
|
-
] as const
|
|
436
|
-
)
|
|
437
|
-
}
|
|
438
|
-
)
|
|
439
|
-
)
|
|
440
|
-
const [rightParallel, rightSequential] = pipe(
|
|
441
|
-
Chunk.headNonEmpty(rightStack),
|
|
442
|
-
reduce(
|
|
443
|
-
[HashSet.empty<unknown>(), Chunk.empty<Cause.Cause<unknown>>()] as const,
|
|
444
|
-
([parallel, sequential], cause) => {
|
|
445
|
-
const [par, seq] = evaluateCause(cause)
|
|
446
|
-
return Option.some(
|
|
447
|
-
[
|
|
448
|
-
pipe(parallel, HashSet.union(par)),
|
|
449
|
-
pipe(sequential, Chunk.appendAll(seq))
|
|
450
|
-
] as const
|
|
451
|
-
)
|
|
452
|
-
}
|
|
453
|
-
)
|
|
454
|
-
)
|
|
455
|
-
if (!Equal.equals(leftParallel, rightParallel)) {
|
|
456
|
-
return false
|
|
457
|
-
}
|
|
458
|
-
leftStack = leftSequential
|
|
459
|
-
rightStack = rightSequential
|
|
460
|
-
}
|
|
461
|
-
return true
|
|
462
|
-
}
|
|
463
|
-
|
|
464
|
-
// -----------------------------------------------------------------------------
|
|
465
|
-
// Flattening
|
|
466
|
-
// -----------------------------------------------------------------------------
|
|
467
|
-
|
|
468
|
-
/**
|
|
469
|
-
* Flattens a cause to a sequence of sets of causes, where each set represents
|
|
470
|
-
* causes that fail in parallel and sequential sets represent causes that fail
|
|
471
|
-
* after each other.
|
|
472
|
-
*
|
|
473
|
-
* @internal
|
|
474
|
-
*/
|
|
475
|
-
const flattenCause = (cause: Cause.Cause<unknown>): Chunk.Chunk<HashSet.HashSet<unknown>> => {
|
|
476
|
-
return flattenCauseLoop(Chunk.of(cause), Chunk.empty())
|
|
477
|
-
}
|
|
478
|
-
|
|
479
|
-
/** @internal */
|
|
480
|
-
const flattenCauseLoop = (
|
|
481
|
-
causes: Chunk.Chunk<Cause.Cause<unknown>>,
|
|
482
|
-
flattened: Chunk.Chunk<HashSet.HashSet<unknown>>
|
|
483
|
-
): Chunk.Chunk<HashSet.HashSet<unknown>> => {
|
|
484
|
-
// eslint-disable-next-line no-constant-condition
|
|
485
|
-
while (1) {
|
|
486
|
-
const [parallel, sequential] = pipe(
|
|
487
|
-
causes,
|
|
488
|
-
Arr.reduce(
|
|
489
|
-
[HashSet.empty<unknown>(), Chunk.empty<Cause.Cause<unknown>>()] as const,
|
|
490
|
-
([parallel, sequential], cause) => {
|
|
491
|
-
const [par, seq] = evaluateCause(cause)
|
|
492
|
-
return [
|
|
493
|
-
pipe(parallel, HashSet.union(par)),
|
|
494
|
-
pipe(sequential, Chunk.appendAll(seq))
|
|
495
|
-
]
|
|
496
|
-
}
|
|
497
|
-
)
|
|
498
|
-
)
|
|
499
|
-
const updated = HashSet.size(parallel) > 0 ?
|
|
500
|
-
pipe(flattened, Chunk.prepend(parallel)) :
|
|
501
|
-
flattened
|
|
502
|
-
if (Chunk.isEmpty(sequential)) {
|
|
503
|
-
return Chunk.reverse(updated)
|
|
504
|
-
}
|
|
505
|
-
causes = sequential
|
|
506
|
-
flattened = updated
|
|
507
|
-
}
|
|
508
|
-
throw new Error(getBugErrorMessage("Cause.flattenCauseLoop"))
|
|
509
|
-
}
|
|
510
|
-
|
|
511
|
-
// -----------------------------------------------------------------------------
|
|
512
|
-
// Finding
|
|
513
|
-
// -----------------------------------------------------------------------------
|
|
514
|
-
|
|
515
|
-
/** @internal */
|
|
516
|
-
export const find = dual<
|
|
517
|
-
<E, Z>(pf: (cause: Cause.Cause<E>) => Option.Option<Z>) => (self: Cause.Cause<E>) => Option.Option<Z>,
|
|
518
|
-
<E, Z>(self: Cause.Cause<E>, pf: (cause: Cause.Cause<E>) => Option.Option<Z>) => Option.Option<Z>
|
|
519
|
-
>(2, <E, Z>(self: Cause.Cause<E>, pf: (cause: Cause.Cause<E>) => Option.Option<Z>) => {
|
|
520
|
-
const stack: Array<Cause.Cause<E>> = [self]
|
|
521
|
-
while (stack.length > 0) {
|
|
522
|
-
const item = stack.pop()!
|
|
523
|
-
const option = pf(item)
|
|
524
|
-
switch (option._tag) {
|
|
525
|
-
case "None": {
|
|
526
|
-
switch (item._tag) {
|
|
527
|
-
case OpCodes.OP_SEQUENTIAL:
|
|
528
|
-
case OpCodes.OP_PARALLEL: {
|
|
529
|
-
stack.push(item.right)
|
|
530
|
-
stack.push(item.left)
|
|
531
|
-
break
|
|
532
|
-
}
|
|
533
|
-
}
|
|
534
|
-
break
|
|
535
|
-
}
|
|
536
|
-
case "Some": {
|
|
537
|
-
return option
|
|
538
|
-
}
|
|
539
|
-
}
|
|
540
|
-
}
|
|
541
|
-
return Option.none()
|
|
542
|
-
})
|
|
543
|
-
|
|
544
|
-
// -----------------------------------------------------------------------------
|
|
545
|
-
// Filtering
|
|
546
|
-
// -----------------------------------------------------------------------------
|
|
547
|
-
|
|
548
|
-
/** @internal */
|
|
549
|
-
export const filter: {
|
|
550
|
-
<E, EB extends E>(
|
|
551
|
-
refinement: Refinement<Cause.Cause<NoInfer<E>>, Cause.Cause<EB>>
|
|
552
|
-
): (self: Cause.Cause<E>) => Cause.Cause<EB>
|
|
553
|
-
<E>(predicate: Predicate<Cause.Cause<NoInfer<E>>>): (self: Cause.Cause<E>) => Cause.Cause<E>
|
|
554
|
-
<E, EB extends E>(self: Cause.Cause<E>, refinement: Refinement<Cause.Cause<E>, Cause.Cause<EB>>): Cause.Cause<EB>
|
|
555
|
-
<E>(self: Cause.Cause<E>, predicate: Predicate<Cause.Cause<E>>): Cause.Cause<E>
|
|
556
|
-
} = dual(
|
|
557
|
-
2,
|
|
558
|
-
<E>(self: Cause.Cause<E>, predicate: Predicate<Cause.Cause<E>>): Cause.Cause<E> =>
|
|
559
|
-
reduceWithContext(self, void 0, FilterCauseReducer(predicate))
|
|
560
|
-
)
|
|
561
|
-
|
|
562
|
-
// -----------------------------------------------------------------------------
|
|
563
|
-
// Evaluation
|
|
564
|
-
// -----------------------------------------------------------------------------
|
|
565
|
-
|
|
566
|
-
/**
|
|
567
|
-
* Takes one step in evaluating a cause, returning a set of causes that fail
|
|
568
|
-
* in parallel and a list of causes that fail sequentially after those causes.
|
|
569
|
-
*
|
|
570
|
-
* @internal
|
|
571
|
-
*/
|
|
572
|
-
const evaluateCause = (
|
|
573
|
-
self: Cause.Cause<unknown>
|
|
574
|
-
): [HashSet.HashSet<unknown>, Chunk.Chunk<Cause.Cause<unknown>>] => {
|
|
575
|
-
let cause: Cause.Cause<unknown> | undefined = self
|
|
576
|
-
const stack: Array<Cause.Cause<unknown>> = []
|
|
577
|
-
let _parallel = HashSet.empty<unknown>()
|
|
578
|
-
let _sequential = Chunk.empty<Cause.Cause<unknown>>()
|
|
579
|
-
while (cause !== undefined) {
|
|
580
|
-
switch (cause._tag) {
|
|
581
|
-
case OpCodes.OP_EMPTY: {
|
|
582
|
-
if (stack.length === 0) {
|
|
583
|
-
return [_parallel, _sequential]
|
|
584
|
-
}
|
|
585
|
-
cause = stack.pop()
|
|
586
|
-
break
|
|
587
|
-
}
|
|
588
|
-
case OpCodes.OP_FAIL: {
|
|
589
|
-
_parallel = HashSet.add(_parallel, Chunk.make(cause._tag, cause.error))
|
|
590
|
-
if (stack.length === 0) {
|
|
591
|
-
return [_parallel, _sequential]
|
|
592
|
-
}
|
|
593
|
-
cause = stack.pop()
|
|
594
|
-
break
|
|
595
|
-
}
|
|
596
|
-
case OpCodes.OP_DIE: {
|
|
597
|
-
_parallel = HashSet.add(_parallel, Chunk.make(cause._tag, cause.defect))
|
|
598
|
-
if (stack.length === 0) {
|
|
599
|
-
return [_parallel, _sequential]
|
|
600
|
-
}
|
|
601
|
-
cause = stack.pop()
|
|
602
|
-
break
|
|
603
|
-
}
|
|
604
|
-
case OpCodes.OP_INTERRUPT: {
|
|
605
|
-
_parallel = HashSet.add(_parallel, Chunk.make(cause._tag, cause.fiberId as unknown))
|
|
606
|
-
if (stack.length === 0) {
|
|
607
|
-
return [_parallel, _sequential]
|
|
608
|
-
}
|
|
609
|
-
cause = stack.pop()
|
|
610
|
-
break
|
|
611
|
-
}
|
|
612
|
-
case OpCodes.OP_SEQUENTIAL: {
|
|
613
|
-
switch (cause.left._tag) {
|
|
614
|
-
case OpCodes.OP_EMPTY: {
|
|
615
|
-
cause = cause.right
|
|
616
|
-
break
|
|
617
|
-
}
|
|
618
|
-
case OpCodes.OP_SEQUENTIAL: {
|
|
619
|
-
cause = sequential(cause.left.left, sequential(cause.left.right, cause.right))
|
|
620
|
-
break
|
|
621
|
-
}
|
|
622
|
-
case OpCodes.OP_PARALLEL: {
|
|
623
|
-
cause = parallel(
|
|
624
|
-
sequential(cause.left.left, cause.right),
|
|
625
|
-
sequential(cause.left.right, cause.right)
|
|
626
|
-
)
|
|
627
|
-
break
|
|
628
|
-
}
|
|
629
|
-
default: {
|
|
630
|
-
_sequential = Chunk.prepend(_sequential, cause.right)
|
|
631
|
-
cause = cause.left
|
|
632
|
-
break
|
|
633
|
-
}
|
|
634
|
-
}
|
|
635
|
-
break
|
|
636
|
-
}
|
|
637
|
-
case OpCodes.OP_PARALLEL: {
|
|
638
|
-
stack.push(cause.right)
|
|
639
|
-
cause = cause.left
|
|
640
|
-
break
|
|
641
|
-
}
|
|
642
|
-
}
|
|
643
|
-
}
|
|
644
|
-
throw new Error(getBugErrorMessage("Cause.evaluateCauseLoop"))
|
|
645
|
-
}
|
|
646
|
-
|
|
647
|
-
// -----------------------------------------------------------------------------
|
|
648
|
-
// Reducing
|
|
649
|
-
// -----------------------------------------------------------------------------
|
|
650
|
-
|
|
651
|
-
/** @internal */
|
|
652
|
-
const SizeCauseReducer: Cause.CauseReducer<unknown, unknown, number> = {
|
|
653
|
-
emptyCase: () => 0,
|
|
654
|
-
failCase: () => 1,
|
|
655
|
-
dieCase: () => 1,
|
|
656
|
-
interruptCase: () => 1,
|
|
657
|
-
sequentialCase: (_, left, right) => left + right,
|
|
658
|
-
parallelCase: (_, left, right) => left + right
|
|
659
|
-
}
|
|
660
|
-
|
|
661
|
-
/** @internal */
|
|
662
|
-
const IsInterruptedOnlyCauseReducer: Cause.CauseReducer<unknown, unknown, boolean> = {
|
|
663
|
-
emptyCase: constTrue,
|
|
664
|
-
failCase: constFalse,
|
|
665
|
-
dieCase: constFalse,
|
|
666
|
-
interruptCase: constTrue,
|
|
667
|
-
sequentialCase: (_, left, right) => left && right,
|
|
668
|
-
parallelCase: (_, left, right) => left && right
|
|
669
|
-
}
|
|
670
|
-
|
|
671
|
-
/** @internal */
|
|
672
|
-
const FilterCauseReducer = <E>(
|
|
673
|
-
predicate: Predicate<Cause.Cause<E>>
|
|
674
|
-
): Cause.CauseReducer<unknown, E, Cause.Cause<E>> => ({
|
|
675
|
-
emptyCase: () => empty,
|
|
676
|
-
failCase: (_, error) => fail(error),
|
|
677
|
-
dieCase: (_, defect) => die(defect),
|
|
678
|
-
interruptCase: (_, fiberId) => interrupt(fiberId),
|
|
679
|
-
sequentialCase: (_, left, right) => {
|
|
680
|
-
if (predicate(left)) {
|
|
681
|
-
if (predicate(right)) {
|
|
682
|
-
return sequential(left, right)
|
|
683
|
-
}
|
|
684
|
-
return left
|
|
685
|
-
}
|
|
686
|
-
if (predicate(right)) {
|
|
687
|
-
return right
|
|
688
|
-
}
|
|
689
|
-
return empty
|
|
690
|
-
},
|
|
691
|
-
parallelCase: (_, left, right) => {
|
|
692
|
-
if (predicate(left)) {
|
|
693
|
-
if (predicate(right)) {
|
|
694
|
-
return parallel(left, right)
|
|
695
|
-
}
|
|
696
|
-
return left
|
|
697
|
-
}
|
|
698
|
-
if (predicate(right)) {
|
|
699
|
-
return right
|
|
700
|
-
}
|
|
701
|
-
return empty
|
|
702
|
-
}
|
|
703
|
-
})
|
|
704
|
-
|
|
705
|
-
/** @internal */
|
|
706
|
-
type CauseCase = SequentialCase | ParallelCase
|
|
707
|
-
|
|
708
|
-
const OP_SEQUENTIAL_CASE = "SequentialCase"
|
|
709
|
-
|
|
710
|
-
const OP_PARALLEL_CASE = "ParallelCase"
|
|
711
|
-
|
|
712
|
-
/** @internal */
|
|
713
|
-
interface SequentialCase {
|
|
714
|
-
readonly _tag: typeof OP_SEQUENTIAL_CASE
|
|
715
|
-
}
|
|
716
|
-
|
|
717
|
-
/** @internal */
|
|
718
|
-
interface ParallelCase {
|
|
719
|
-
readonly _tag: typeof OP_PARALLEL_CASE
|
|
720
|
-
}
|
|
721
|
-
|
|
722
|
-
/** @internal */
|
|
723
|
-
export const match = dual<
|
|
724
|
-
<Z, E>(
|
|
725
|
-
options: {
|
|
726
|
-
readonly onEmpty: Z
|
|
727
|
-
readonly onFail: (error: E) => Z
|
|
728
|
-
readonly onDie: (defect: unknown) => Z
|
|
729
|
-
readonly onInterrupt: (fiberId: FiberId.FiberId) => Z
|
|
730
|
-
readonly onSequential: (left: Z, right: Z) => Z
|
|
731
|
-
readonly onParallel: (left: Z, right: Z) => Z
|
|
732
|
-
}
|
|
733
|
-
) => (self: Cause.Cause<E>) => Z,
|
|
734
|
-
<Z, E>(
|
|
735
|
-
self: Cause.Cause<E>,
|
|
736
|
-
options: {
|
|
737
|
-
readonly onEmpty: Z
|
|
738
|
-
readonly onFail: (error: E) => Z
|
|
739
|
-
readonly onDie: (defect: unknown) => Z
|
|
740
|
-
readonly onInterrupt: (fiberId: FiberId.FiberId) => Z
|
|
741
|
-
readonly onSequential: (left: Z, right: Z) => Z
|
|
742
|
-
readonly onParallel: (left: Z, right: Z) => Z
|
|
743
|
-
}
|
|
744
|
-
) => Z
|
|
745
|
-
>(2, (self, { onDie, onEmpty, onFail, onInterrupt, onParallel, onSequential }) => {
|
|
746
|
-
return reduceWithContext(self, void 0, {
|
|
747
|
-
emptyCase: () => onEmpty,
|
|
748
|
-
failCase: (_, error) => onFail(error),
|
|
749
|
-
dieCase: (_, defect) => onDie(defect),
|
|
750
|
-
interruptCase: (_, fiberId) => onInterrupt(fiberId),
|
|
751
|
-
sequentialCase: (_, left, right) => onSequential(left, right),
|
|
752
|
-
parallelCase: (_, left, right) => onParallel(left, right)
|
|
753
|
-
})
|
|
754
|
-
})
|
|
755
|
-
|
|
756
|
-
/** @internal */
|
|
757
|
-
export const reduce = dual<
|
|
758
|
-
<Z, E>(zero: Z, pf: (accumulator: Z, cause: Cause.Cause<E>) => Option.Option<Z>) => (self: Cause.Cause<E>) => Z,
|
|
759
|
-
<Z, E>(self: Cause.Cause<E>, zero: Z, pf: (accumulator: Z, cause: Cause.Cause<E>) => Option.Option<Z>) => Z
|
|
760
|
-
>(3, <Z, E>(self: Cause.Cause<E>, zero: Z, pf: (accumulator: Z, cause: Cause.Cause<E>) => Option.Option<Z>) => {
|
|
761
|
-
let accumulator: Z = zero
|
|
762
|
-
let cause: Cause.Cause<E> | undefined = self
|
|
763
|
-
const causes: Array<Cause.Cause<E>> = []
|
|
764
|
-
while (cause !== undefined) {
|
|
765
|
-
const option = pf(accumulator, cause)
|
|
766
|
-
accumulator = Option.isSome(option) ? option.value : accumulator
|
|
767
|
-
switch (cause._tag) {
|
|
768
|
-
case OpCodes.OP_SEQUENTIAL: {
|
|
769
|
-
causes.push(cause.right)
|
|
770
|
-
cause = cause.left
|
|
771
|
-
break
|
|
772
|
-
}
|
|
773
|
-
case OpCodes.OP_PARALLEL: {
|
|
774
|
-
causes.push(cause.right)
|
|
775
|
-
cause = cause.left
|
|
776
|
-
break
|
|
777
|
-
}
|
|
778
|
-
default: {
|
|
779
|
-
cause = undefined
|
|
780
|
-
break
|
|
781
|
-
}
|
|
782
|
-
}
|
|
783
|
-
if (cause === undefined && causes.length > 0) {
|
|
784
|
-
cause = causes.pop()!
|
|
785
|
-
}
|
|
786
|
-
}
|
|
787
|
-
return accumulator
|
|
788
|
-
})
|
|
789
|
-
|
|
790
|
-
/** @internal */
|
|
791
|
-
export const reduceWithContext = dual<
|
|
792
|
-
<C, E, Z>(context: C, reducer: Cause.CauseReducer<C, E, Z>) => (self: Cause.Cause<E>) => Z,
|
|
793
|
-
<C, E, Z>(self: Cause.Cause<E>, context: C, reducer: Cause.CauseReducer<C, E, Z>) => Z
|
|
794
|
-
>(3, <C, E, Z>(self: Cause.Cause<E>, context: C, reducer: Cause.CauseReducer<C, E, Z>) => {
|
|
795
|
-
const input: Array<Cause.Cause<E>> = [self]
|
|
796
|
-
const output: Array<Either.Either<Z, CauseCase>> = []
|
|
797
|
-
while (input.length > 0) {
|
|
798
|
-
const cause = input.pop()!
|
|
799
|
-
switch (cause._tag) {
|
|
800
|
-
case OpCodes.OP_EMPTY: {
|
|
801
|
-
output.push(Either.right(reducer.emptyCase(context)))
|
|
802
|
-
break
|
|
803
|
-
}
|
|
804
|
-
case OpCodes.OP_FAIL: {
|
|
805
|
-
output.push(Either.right(reducer.failCase(context, cause.error)))
|
|
806
|
-
break
|
|
807
|
-
}
|
|
808
|
-
case OpCodes.OP_DIE: {
|
|
809
|
-
output.push(Either.right(reducer.dieCase(context, cause.defect)))
|
|
810
|
-
break
|
|
811
|
-
}
|
|
812
|
-
case OpCodes.OP_INTERRUPT: {
|
|
813
|
-
output.push(Either.right(reducer.interruptCase(context, cause.fiberId)))
|
|
814
|
-
break
|
|
815
|
-
}
|
|
816
|
-
case OpCodes.OP_SEQUENTIAL: {
|
|
817
|
-
input.push(cause.right)
|
|
818
|
-
input.push(cause.left)
|
|
819
|
-
output.push(Either.left({ _tag: OP_SEQUENTIAL_CASE }))
|
|
820
|
-
break
|
|
821
|
-
}
|
|
822
|
-
case OpCodes.OP_PARALLEL: {
|
|
823
|
-
input.push(cause.right)
|
|
824
|
-
input.push(cause.left)
|
|
825
|
-
output.push(Either.left({ _tag: OP_PARALLEL_CASE }))
|
|
826
|
-
break
|
|
827
|
-
}
|
|
828
|
-
}
|
|
829
|
-
}
|
|
830
|
-
const accumulator: Array<Z> = []
|
|
831
|
-
while (output.length > 0) {
|
|
832
|
-
const either = output.pop()!
|
|
833
|
-
switch (either._tag) {
|
|
834
|
-
case "Left": {
|
|
835
|
-
switch (either.left._tag) {
|
|
836
|
-
case OP_SEQUENTIAL_CASE: {
|
|
837
|
-
const left = accumulator.pop()!
|
|
838
|
-
const right = accumulator.pop()!
|
|
839
|
-
const value = reducer.sequentialCase(context, left, right)
|
|
840
|
-
accumulator.push(value)
|
|
841
|
-
break
|
|
842
|
-
}
|
|
843
|
-
case OP_PARALLEL_CASE: {
|
|
844
|
-
const left = accumulator.pop()!
|
|
845
|
-
const right = accumulator.pop()!
|
|
846
|
-
const value = reducer.parallelCase(context, left, right)
|
|
847
|
-
accumulator.push(value)
|
|
848
|
-
break
|
|
849
|
-
}
|
|
850
|
-
}
|
|
851
|
-
break
|
|
852
|
-
}
|
|
853
|
-
case "Right": {
|
|
854
|
-
accumulator.push(either.right)
|
|
855
|
-
break
|
|
856
|
-
}
|
|
857
|
-
}
|
|
858
|
-
}
|
|
859
|
-
if (accumulator.length === 0) {
|
|
860
|
-
throw new Error(
|
|
861
|
-
"BUG: Cause.reduceWithContext - please report an issue at https://github.com/Effect-TS/effect/issues"
|
|
862
|
-
)
|
|
863
|
-
}
|
|
864
|
-
return accumulator.pop()!
|
|
865
|
-
})
|
|
866
|
-
|
|
867
|
-
// -----------------------------------------------------------------------------
|
|
868
|
-
// Pretty Printing
|
|
869
|
-
// -----------------------------------------------------------------------------
|
|
870
|
-
|
|
871
|
-
/** @internal */
|
|
872
|
-
export const pretty = <E>(cause: Cause.Cause<E>, options?: {
|
|
873
|
-
readonly renderErrorCause?: boolean | undefined
|
|
874
|
-
}): string => {
|
|
875
|
-
if (isInterruptedOnly(cause)) {
|
|
876
|
-
return "All fibers interrupted without errors."
|
|
877
|
-
}
|
|
878
|
-
return prettyErrors<E>(cause).map(function(e) {
|
|
879
|
-
if (options?.renderErrorCause !== true || e.cause === undefined) {
|
|
880
|
-
return e.stack
|
|
881
|
-
}
|
|
882
|
-
return `${e.stack} {\n${renderErrorCause(e.cause as PrettyError, " ")}\n}`
|
|
883
|
-
}).join("\n")
|
|
884
|
-
}
|
|
885
|
-
|
|
886
|
-
const renderErrorCause = (cause: PrettyError, prefix: string) => {
|
|
887
|
-
const lines = cause.stack!.split("\n")
|
|
888
|
-
let stack = `${prefix}[cause]: ${lines[0]}`
|
|
889
|
-
for (let i = 1, len = lines.length; i < len; i++) {
|
|
890
|
-
stack += `\n${prefix}${lines[i]}`
|
|
891
|
-
}
|
|
892
|
-
if (cause.cause) {
|
|
893
|
-
stack += ` {\n${renderErrorCause(cause.cause as PrettyError, `${prefix} `)}\n${prefix}}`
|
|
894
|
-
}
|
|
895
|
-
return stack
|
|
896
|
-
}
|
|
897
|
-
|
|
898
|
-
/** @internal */
|
|
899
|
-
export class PrettyError extends globalThis.Error implements Cause.PrettyError {
|
|
900
|
-
span: undefined | Span = undefined
|
|
901
|
-
constructor(originalError: unknown) {
|
|
902
|
-
const originalErrorIsObject = typeof originalError === "object" && originalError !== null
|
|
903
|
-
const prevLimit = Error.stackTraceLimit
|
|
904
|
-
Error.stackTraceLimit = 1
|
|
905
|
-
super(
|
|
906
|
-
prettyErrorMessage(originalError),
|
|
907
|
-
originalErrorIsObject && "cause" in originalError && typeof originalError.cause !== "undefined"
|
|
908
|
-
? { cause: new PrettyError(originalError.cause) }
|
|
909
|
-
: undefined
|
|
910
|
-
)
|
|
911
|
-
if (this.message === "") {
|
|
912
|
-
this.message = "An error has occurred"
|
|
913
|
-
}
|
|
914
|
-
Error.stackTraceLimit = prevLimit
|
|
915
|
-
this.name = originalError instanceof Error ? originalError.name : "Error"
|
|
916
|
-
if (originalErrorIsObject) {
|
|
917
|
-
if (spanSymbol in originalError) {
|
|
918
|
-
this.span = originalError[spanSymbol] as Span
|
|
919
|
-
}
|
|
920
|
-
Object.keys(originalError).forEach((key) => {
|
|
921
|
-
if (!(key in this)) {
|
|
922
|
-
// @ts-expect-error
|
|
923
|
-
this[key] = originalError[key]
|
|
924
|
-
}
|
|
925
|
-
})
|
|
926
|
-
}
|
|
927
|
-
this.stack = prettyErrorStack(
|
|
928
|
-
`${this.name}: ${this.message}`,
|
|
929
|
-
originalError instanceof Error && originalError.stack
|
|
930
|
-
? originalError.stack
|
|
931
|
-
: "",
|
|
932
|
-
this.span
|
|
933
|
-
)
|
|
934
|
-
}
|
|
935
|
-
}
|
|
936
|
-
|
|
937
|
-
/**
|
|
938
|
-
* A utility function for generating human-readable error messages from a generic error of type `unknown`.
|
|
939
|
-
*
|
|
940
|
-
* Rules:
|
|
941
|
-
*
|
|
942
|
-
* 1) If the input `u` is already a string, it's considered a message.
|
|
943
|
-
* 2) If `u` is an Error instance with a message defined, it uses the message.
|
|
944
|
-
* 3) If `u` has a user-defined `toString()` method, it uses that method.
|
|
945
|
-
* 4) Otherwise, it uses `Inspectable.stringifyCircular` to produce a string representation and uses it as the error message,
|
|
946
|
-
* with "Error" added as a prefix.
|
|
947
|
-
*
|
|
948
|
-
* @internal
|
|
949
|
-
*/
|
|
950
|
-
export const prettyErrorMessage = (u: unknown): string => {
|
|
951
|
-
// 1)
|
|
952
|
-
if (typeof u === "string") {
|
|
953
|
-
return u
|
|
954
|
-
}
|
|
955
|
-
// 2)
|
|
956
|
-
if (typeof u === "object" && u !== null && u instanceof Error) {
|
|
957
|
-
return u.message
|
|
958
|
-
}
|
|
959
|
-
// 3)
|
|
960
|
-
try {
|
|
961
|
-
if (
|
|
962
|
-
hasProperty(u, "toString") &&
|
|
963
|
-
isFunction(u["toString"]) &&
|
|
964
|
-
u["toString"] !== Object.prototype.toString &&
|
|
965
|
-
u["toString"] !== globalThis.Array.prototype.toString
|
|
966
|
-
) {
|
|
967
|
-
return u["toString"]()
|
|
968
|
-
}
|
|
969
|
-
} catch {
|
|
970
|
-
// something's off, rollback to json
|
|
971
|
-
}
|
|
972
|
-
// 4)
|
|
973
|
-
return stringifyCircular(u)
|
|
974
|
-
}
|
|
975
|
-
|
|
976
|
-
const locationRegex = /\((.*)\)/g
|
|
977
|
-
|
|
978
|
-
/** @internal */
|
|
979
|
-
export const spanToTrace = globalValue("effect/Tracer/spanToTrace", () => new WeakMap())
|
|
980
|
-
|
|
981
|
-
const prettyErrorStack = (message: string, stack: string, span?: Span | undefined): string => {
|
|
982
|
-
const out: Array<string> = [message]
|
|
983
|
-
const lines = stack.startsWith(message) ? stack.slice(message.length).split("\n") : stack.split("\n")
|
|
984
|
-
|
|
985
|
-
for (let i = 1; i < lines.length; i++) {
|
|
986
|
-
if (lines[i].includes(" at new BaseEffectError") || lines[i].includes(" at new YieldableError")) {
|
|
987
|
-
i++
|
|
988
|
-
continue
|
|
989
|
-
}
|
|
990
|
-
if (lines[i].includes("Generator.next")) {
|
|
991
|
-
break
|
|
992
|
-
}
|
|
993
|
-
if (lines[i].includes("effect_internal_function")) {
|
|
994
|
-
break
|
|
995
|
-
}
|
|
996
|
-
out.push(
|
|
997
|
-
lines[i]
|
|
998
|
-
.replace(/at .*effect_instruction_i.*\((.*)\)/, "at $1")
|
|
999
|
-
.replace(/EffectPrimitive\.\w+/, "<anonymous>")
|
|
1000
|
-
)
|
|
1001
|
-
}
|
|
1002
|
-
|
|
1003
|
-
if (span) {
|
|
1004
|
-
let current: Span | AnySpan | undefined = span
|
|
1005
|
-
let i = 0
|
|
1006
|
-
while (current && current._tag === "Span" && i < 10) {
|
|
1007
|
-
const stackFn = spanToTrace.get(current)
|
|
1008
|
-
if (typeof stackFn === "function") {
|
|
1009
|
-
const stack = stackFn()
|
|
1010
|
-
if (typeof stack === "string") {
|
|
1011
|
-
const locationMatchAll = stack.matchAll(locationRegex)
|
|
1012
|
-
let match = false
|
|
1013
|
-
for (const [, location] of locationMatchAll) {
|
|
1014
|
-
match = true
|
|
1015
|
-
out.push(` at ${current.name} (${location})`)
|
|
1016
|
-
}
|
|
1017
|
-
if (!match) {
|
|
1018
|
-
out.push(` at ${current.name} (${stack.replace(/^at /, "")})`)
|
|
1019
|
-
}
|
|
1020
|
-
} else {
|
|
1021
|
-
out.push(` at ${current.name}`)
|
|
1022
|
-
}
|
|
1023
|
-
} else {
|
|
1024
|
-
out.push(` at ${current.name}`)
|
|
1025
|
-
}
|
|
1026
|
-
current = Option.getOrUndefined(current.parent)
|
|
1027
|
-
i++
|
|
1028
|
-
}
|
|
1029
|
-
}
|
|
1030
|
-
|
|
1031
|
-
return out.join("\n")
|
|
1032
|
-
}
|
|
1033
|
-
|
|
1034
|
-
/** @internal */
|
|
1035
|
-
export const spanSymbol = Symbol.for("effect/SpanAnnotation")
|
|
1036
|
-
|
|
1037
|
-
/** @internal */
|
|
1038
|
-
export const prettyErrors = <E>(cause: Cause.Cause<E>): Array<PrettyError> =>
|
|
1039
|
-
reduceWithContext(cause, void 0, {
|
|
1040
|
-
emptyCase: (): Array<PrettyError> => [],
|
|
1041
|
-
dieCase: (_, unknownError) => {
|
|
1042
|
-
return [new PrettyError(unknownError)]
|
|
1043
|
-
},
|
|
1044
|
-
failCase: (_, error) => {
|
|
1045
|
-
return [new PrettyError(error)]
|
|
1046
|
-
},
|
|
1047
|
-
interruptCase: () => [],
|
|
1048
|
-
parallelCase: (_, l, r) => [...l, ...r],
|
|
1049
|
-
sequentialCase: (_, l, r) => [...l, ...r]
|
|
1050
|
-
})
|