How would one cope with a fatalError in a server written in Swift?
Asked Answered
A

0

6

I am in the process of evaluating Swift as a server-side language for a non-trivial web application. The reason for choosing Swift is mostly to be able to share code with an existing iOS app written in Swift. I have created a small, mostly IO-bound CRUD application (using Vapor 3.0 if that matters) to evaluate and, overall, the experience has been quite neutral. I am not going into the details as they are unrelated to this question.

The Swift language by design offers no way to recover from fatal errors, like the ones you would get by unwrapping an Optional with a nil value.

I don't understand how this design characteristic is supposed to be handled in practice in server applications. Even if I make sure to never, ever force-unwrap an Optional in my code for example, how can I trust that no library author does it either? How do I ensure that if a thread encounters a fatal error, it won't bring the whole server crashing down with it?

So my question is, what are some good practices to handle these situations? Am I supposed to run my application via fcgi? Supervise it by some external process and restart-on-crash in some way? This can't be acceptable for example in a complex application with lots of server-side state and expensive processing, which would be one of the main reasons of choosing a fast compiled language in the first place.

Apollus answered 26/6, 2018 at 11:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.