@@ -8,7 +8,7 @@ import * as FiberId from "../FiberId.js"
8
8
import type * as FiberRef from "../FiberRef.js"
9
9
import * as FiberRefs from "../FiberRefs.js"
10
10
import { dual , pipe } from "../Function.js"
11
- import { format , NodeInspectSymbol } from "../Inspectable.js"
11
+ import * as Inspectable from "../Inspectable.js"
12
12
import * as Option from "../Option.js"
13
13
import { pipeArguments } from "../Pipeable.js"
14
14
import * as Predicate from "../Predicate.js"
@@ -131,38 +131,22 @@ export const unsafeRunSync = <R>(runtime: Runtime.Runtime<R>) => <A, E>(effect:
131
131
}
132
132
}
133
133
134
+ class AsyncFiberExceptionImpl < A , E = never > extends Error implements Runtime . AsyncFiberException < A , E > {
135
+ readonly _tag = "AsyncFiberException"
136
+ constructor ( readonly fiber : Fiber . RuntimeFiber < A , E > ) {
137
+ super (
138
+ `Fiber #${ fiber . id ( ) . id } cannot be be resolved synchronously, this is caused by using runSync on an effect that performs async work`
139
+ )
140
+ this . name = this . _tag
141
+ this . stack = this . message
142
+ }
143
+ }
144
+
134
145
const asyncFiberException = < A , E > ( fiber : Fiber . RuntimeFiber < A , E > ) : Runtime . AsyncFiberException < A , E > => {
135
146
const limit = Error . stackTraceLimit
136
147
Error . stackTraceLimit = 0
137
- const error = ( new Error ( ) ) as any
148
+ const error = new AsyncFiberExceptionImpl ( fiber )
138
149
Error . stackTraceLimit = limit
139
- const message =
140
- `Fiber #${ fiber . id ( ) . id } cannot be be resolved synchronously, this is caused by using runSync on an effect that performs async work`
141
- const _tag = "AsyncFiberException"
142
- Object . defineProperties ( error , {
143
- _tag : {
144
- value : _tag
145
- } ,
146
- fiber : {
147
- value : fiber
148
- } ,
149
- message : {
150
- value : message
151
- } ,
152
- name : {
153
- value : _tag
154
- } ,
155
- toString : {
156
- get ( ) {
157
- return ( ) => message
158
- }
159
- } ,
160
- [ NodeInspectSymbol ] : {
161
- get ( ) {
162
- return ( ) => message
163
- }
164
- }
165
- } )
166
150
return error
167
151
}
168
152
@@ -177,37 +161,46 @@ export const FiberFailureCauseId: Runtime.FiberFailureCauseId = Symbol.for(
177
161
"effect/Runtime/FiberFailure/Cause"
178
162
) as any
179
163
180
- type Mutable < A > = {
181
- - readonly [ k in keyof A ] : A [ k ]
182
- }
164
+ class FiberFailureImpl extends Error implements Runtime . FiberFailure {
165
+ readonly [ FiberFailureId ] : Runtime . FiberFailureId
166
+ readonly [ FiberFailureCauseId ] : Cause . Cause < unknown >
167
+ constructor ( cause : Cause . Cause < unknown > ) {
168
+ super ( )
169
+
170
+ this [ FiberFailureId ] = FiberFailureId
171
+ this [ FiberFailureCauseId ] = cause
172
+
173
+ const prettyErrors = InternalCause . prettyErrors ( cause )
174
+ if ( prettyErrors . length > 0 ) {
175
+ const head = prettyErrors [ 0 ]
176
+ this . name = head . message . split ( ":" ) [ 0 ]
177
+ this . message = head . message . substring ( this . name . length + 2 )
178
+ this . stack = InternalCause . pretty ( cause )
179
+ }
183
180
184
- /** @internal */
185
- export const fiberFailure = < E > ( cause : Cause . Cause < E > ) : Runtime . FiberFailure => {
186
- const limit = Error . stackTraceLimit
187
- Error . stackTraceLimit = 0
188
- const error = ( new Error ( ) ) as Mutable < Runtime . FiberFailure >
189
- Error . stackTraceLimit = limit
190
- const prettyErrors = InternalCause . prettyErrors ( cause )
191
- if ( prettyErrors . length > 0 ) {
192
- const head = prettyErrors [ 0 ]
193
- error . name = head . message . split ( ":" ) [ 0 ]
194
- error . message = head . message . substring ( error . name . length + 2 )
195
- error . stack = InternalCause . pretty ( cause )
181
+ this . name = `(FiberFailure) ${ this . name } `
196
182
}
197
- error [ FiberFailureId ] = FiberFailureId
198
- error [ FiberFailureCauseId ] = cause
199
- error . toJSON = ( ) => {
183
+
184
+ toJSON ( ) : unknown {
200
185
return {
201
186
_id : "FiberFailure" ,
202
- cause : cause . toJSON ( )
187
+ cause : this [ FiberFailureCauseId ] . toJSON ( )
203
188
}
204
189
}
205
- error . toString = ( ) => {
206
- return format ( error . toJSON ( ) )
190
+ toString ( ) : string {
191
+ return "(FiberFailure) " + InternalCause . pretty ( this [ FiberFailureCauseId ] )
207
192
}
208
- error [ NodeInspectSymbol ] = ( ) => {
209
- return error . toJSON ( )
193
+ [ Inspectable . NodeInspectSymbol ] ( ) : unknown {
194
+ return this . toString ( )
210
195
}
196
+ }
197
+
198
+ /** @internal */
199
+ export const fiberFailure = < E > ( cause : Cause . Cause < E > ) : Runtime . FiberFailure => {
200
+ const limit = Error . stackTraceLimit
201
+ Error . stackTraceLimit = 0
202
+ const error = new FiberFailureImpl ( cause )
203
+ Error . stackTraceLimit = limit
211
204
return error
212
205
}
213
206
0 commit comments