| 14692 | } |
| 14693 | |
| 14694 | function fnApply(options: { |
| 14695 | readonly self: any |
| 14696 | readonly body: Function |
| 14697 | readonly args: Array<any> |
| 14698 | readonly pipeables: Array<any> |
| 14699 | readonly spanName: string |
| 14700 | readonly spanOptions: Tracer.SpanOptions |
| 14701 | readonly errorDef: Error |
| 14702 | readonly errorCall: Error |
| 14703 | }) { |
| 14704 | let effect: Effect<any, any, any> |
| 14705 | let fnError: any = undefined |
| 14706 | if (isGeneratorFunction(options.body)) { |
| 14707 | effect = core.fromIterator(() => options.body.apply(options.self, options.args)) |
| 14708 | } else { |
| 14709 | try { |
| 14710 | effect = options.body.apply(options.self, options.args) |
| 14711 | } catch (error) { |
| 14712 | fnError = error |
| 14713 | effect = die(error) |
| 14714 | } |
| 14715 | } |
| 14716 | if (options.pipeables.length > 0) { |
| 14717 | try { |
| 14718 | for (const x of options.pipeables) { |
| 14719 | effect = x(effect, ...options.args) |
| 14720 | } |
| 14721 | } catch (error) { |
| 14722 | effect = fnError |
| 14723 | ? failCause(internalCause.sequential( |
| 14724 | internalCause.die(fnError), |
| 14725 | internalCause.die(error) |
| 14726 | )) |
| 14727 | : die(error) |
| 14728 | } |
| 14729 | } |
| 14730 | |
| 14731 | let cache: false | string = false |
| 14732 | const captureStackTrace = () => { |
| 14733 | if (cache !== false) { |
| 14734 | return cache |
| 14735 | } |
| 14736 | if (options.errorCall.stack) { |
| 14737 | const stackDef = options.errorDef.stack!.trim().split("\n") |
| 14738 | const stackCall = options.errorCall.stack.trim().split("\n") |
| 14739 | let endStackDef = stackDef.slice(2).join("\n").trim() |
| 14740 | if (!endStackDef.includes(`(`)) { |
| 14741 | endStackDef = endStackDef.replace(/at (.*)/, "at ($1)") |
| 14742 | } |
| 14743 | let endStackCall = stackCall.slice(2).join("\n").trim() |
| 14744 | if (!endStackCall.includes(`(`)) { |
| 14745 | endStackCall = endStackCall.replace(/at (.*)/, "at ($1)") |
| 14746 | } |
| 14747 | cache = `${endStackDef}\n${endStackCall}` |
| 14748 | return cache |
| 14749 | } |
| 14750 | } |
| 14751 | const opts: any = (options.spanOptions && "captureStackTrace" in options.spanOptions) |