Stream: ideas

Topic: Task.onFail helpers


view this post on Zulip Travis (Oct 12 2022 at 15:37):

During the following discussion in the 'print error if file not found' topic, it came up that maybe we should reconsider Task.onFail's behavior or name. Or perhaps add one or both of these two Ttask helpers

  1. a helper to do a task and still fail with the original error
    |> File.readUtf8
    |> Task.onFail (\e ->
      _ <- Stderr.line "oops" |> Task.await
      Task.fail e
    )
    |> Task.await
  1. a helper to substitute a success for failure and continue the Task chain
  |> File.readUtf8
  |> Task.onFail (\_ -> Task.succeed "Some alternate value")
  |> Task.await

https://roc.zulipchat.com/#narrow/stream/231634-beginners/topic/.E2.9C.94.20print.20err.20if.20file.20not.20found/near/303638815

@Brendan Hansknecht wrote

So the current implementation of onFail doesn't work the way we expected here.
I guess onFail is really "if I fail, try to recover and continue by doing this".
You want, "if I fail, do this, but stay as a failure".
Seems like a generally useful Task function that we are missing. Also a possible naming confusion/conflict.


Last updated: Jun 16 2026 at 16:19 UTC