Skip to content

guide/async.md §3: onFlush(() => { saveError := "" }) erases an error thrown before the action's first await #52

Open

Description

@revosw

Filed with Opus 5.5. I personally don't have the required understanding to know whether it's something worth fixing, but I had a stab at converting my web app to use reactivescript. Very excited for the development, so I'll continue to file (hopefully) useful issues, based on the migration efforts

Versions: spec, interpreter and runtime on main at 08255de (also 0.1.0).

guide/async.md §3 clears the old error at the top of the action with onFlush(() => { saveError := "" }) and writes the new error in the catch. If the body fails before its first await, the catch's write lands in the run's own instant. The onFlush run then follows and clears it. The interpreter agrees:

error Early() => "early"

export default component App() {
  source err: string := "none"
  action go() {
    onFlush(() => { err := "" })
    try {
      throw Early()
      await save(1)
    } catch (e) {
      err := `caught ${e.message}`
    }
  }
  <div><button onClick={() => { go() }}>go</button><p>{err}</p></div>
}
instant action frame
0 mount go none
1 go() go caught early
2 (the onFlush run) go

In the browser both instants land in one frame, so the user never sees the error. In our case the error was a synchronous throw from inside the runtime, and it vanished silently.

This follows from EF-8, so it isn't a runtime bug, but the guide presents the idiom as the general pattern. Options: add a caveat to the guide, or recommend a form that doesn't lose early failures. I haven't verified which form the maintainers would prefer, e.g. writing the error via onFlush in the catch as well.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions