Add `underlyingError: Error?` property to Error

Exactly, yes!

My understanding of this has been heavily influenced by this post on the 'typed throws' pitch:

So for these reasons I think it would probably be best to leave underlyingError: Error? as untyped, because I imagine that in most cases underlyingError: Error? will only be of use in the 'generic fall-back' situation described above – to provide a better avenue for cross-module diagnostics.

In the case where you do know the type of the underlying error that you can recover from, you'd probably be better off encoding it into your own Error type, even if that does lead to some duplication.

1 Like