Skip to content
This repository has been archived by the owner on Sep 14, 2023. It is now read-only.

Commit

Permalink
Revert "feat: rework trace (#1062)"
Browse files Browse the repository at this point in the history
This reverts commit 47c4292.
  • Loading branch information
tjjfvi authored and ryanleecode committed Jun 13, 2023
1 parent 57f09bd commit 27299d4
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 236 deletions.
1 change: 0 additions & 1 deletion examples/dev/metadata.eg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
* even plain-text descriptions. This metadata serves as the basis off of which we
* generate chain-specific APIs. Unless you are building an advanced Capi-based library,
* chances are that you don't need to work with the metadata directly.
* @test_skip
*/

import { polkadotDev } from "@capi/polkadot-dev"
Expand Down
27 changes: 21 additions & 6 deletions rune/Rune.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { deferred } from "../deps/std/async.ts"
import { getOrInit } from "../util/state.ts"
import { EventSource, Receipt, Timeline } from "./Timeline.ts"
import { Trace } from "./Trace.ts"

// Hack to work around circularity issues
// @deno-types="./_empty.d.ts"
Expand Down Expand Up @@ -188,13 +187,11 @@ export class Rune<out T, out U = never> {
return Rune.new(RunPlaceholder)
}

into<A extends unknown[], C extends Rune<any, any>>(
into<A extends unknown[], C>(
ctor: new(_prime: (batch: Batch) => Run<T, U | RunicArgs.U<A>>, ...args: A) => C,
...args: A
): C {
const rune = new ctor(this._prime, ...args)
rune._trace = this._trace
return rune
return new ctor(this._prime, ...args)
}

as<R>(this: R, _ctor: new(_prime: (batch: Batch) => Run<T, U>, ...args: any) => R): R {
Expand Down Expand Up @@ -244,7 +241,16 @@ export abstract class Run<T, U> {
this._currentReceipt.novel = true
}
this._currentTime = time
this._currentPromise = this.trace.runAsync(() => this._evaluate(time, this._currentReceipt))
this._currentPromise = (async () => {
try {
return await this._evaluate(time, this._currentReceipt)
} catch (e) {
if (e instanceof Error) {
e.message = `${e.message.trimEnd()}\n\n${this.trace.from}\n`
}
throw e
}
})()
}
const _receipt = this._currentReceipt
try {
Expand Down Expand Up @@ -426,3 +432,12 @@ export namespace RunicArgs {
: Object.fromEntries(Object.entries(args).map(([k, v]) => [k, Rune.resolve(v)]))
}
}

export class Trace extends Error {
declare from: string
constructor(name: string) {
super()
Object.defineProperty(this, "name", { value: name })
Object.defineProperty(this, "from", { value: ("from " + this.stack).replace(/^/gm, " ") })
}
}
45 changes: 0 additions & 45 deletions rune/Trace.test.ts

This file was deleted.

184 changes: 0 additions & 184 deletions rune/Trace.ts

This file was deleted.

0 comments on commit 27299d4

Please sign in to comment.