Raised Error context and diagnostics

What's the best way to construct the context for a raised Error in Swift for diagnostics/logging purposes?

The obvious diagnostic would be to get the source error and the call stack, but I feel that that's a no-go in Swift for some reason. I'm also not sure how it would work across asynchronous contexts.

The other way is to construct some kind of Frankenstein Matryoshka Russian doll style Error type that builds itself up the stack, but that adds a ton of boiler plate.

(I've seen some cases where people discard the original error and replace it with a more generalised error, but that seems the worst of both worlds – all the boilerplate, none of the context!)

I'm finding it difficult to uncover any unifying philosophy for error handling in Swift that accommodates these kind of diagnostics. Is there some source material I can read hidden somewhere?

Terms of Service

Privacy Policy

Cookie Policy