UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

Catching complicated errors including generic error types

Forums > Swift

I'm writing some code that uses a library written by a colleague that is not available to answer questions for an extended period of time, so I bring this question here. Since the code is internal stuff, I'll be substituting some names so bear with me. :)

The library is throwing an error whose type is fairly complex and involves generics with parameters. When I dump() the error to console, I get something like this:

▿ ToolRuntime.ToolError.retryError
  ▿ retryError: ToolRuntime.ToolManagerError<DataLib.LookupDataValueError>.overseer
    ▿ overseer: (2 elements)
      ▿ .0: DataLib.LookupDataValueError.recordNotFoundException
        ▿ recordNotFoundException: DataLib.RecordNotFoundException

And so on (there's more but just data attached to the error that should be irrelevant -- but let me know if I'm wrong). Element 1 in the array overseer is just the raw data returned from the server that was decoded into the error object.

I can't seem to catch this error. I need to know if this retryError occurs, but nothing I've tried seems to result in catching it. Instead, the retryError always falls through to my default error handler. I would expect that catch ToolRuntime.ToolError.retryError would do the job, but it doesn't. If anyone can look at that and give me an idea what I'm missing, I'd sure appreciate it.

2      

TAKE YOUR SKILLS TO THE NEXT LEVEL If you like Hacking with Swift, you'll love Hacking with Swift+ – it's my premium service where you can learn advanced Swift and SwiftUI, functional programming, algorithms, and more. Plus it comes with stacks of benefits, including monthly live streams, downloadable projects, a 20% discount on all books, and free gifts!

Find out more

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.