Actix_web: handle errors in configure()


I have this snippet of code in my application:

    server::new(move || {

The configure method works fine, since the configure_app method returns an App<MyAppConfig>.

Now, I modified the configure_app method so it returns a Result<App<MyAppConfig>, MyCustomError> because I perform some operations that might fail during configuration.

My question is: how can I make it work with the above syntax ?

I would like to avoid doing this:

.configure(|app| configure_app(app).unwrap())


Actix doesn’t look like it has a way to handle fallible functions, so using a closure is you only choice.



I can’t return from a function from a closure, right ? How could I return from the function if configure_app returns an error ?

Ideally, I know it doesn’t work and that’s not how it’s supposed to be done, but I’d like something like this:

.configure(|app| match configure_app(app){
   Ok(config) => config,
   Err(_) => return Err("damned") // I mean, return from function, not from the closure


So, I looked at the source code for actix, configure is a method to allow the builder pattern, and only calls the closure passed into it with self. So you could just call the function normally with the app and propogate the result.

let app = App::new();