mirror of
https://github.com/mailscope/kumomta.git
synced 2026-09-08 03:28:57 +00:00
server-common: re-print initialization errors
If init fails, we log an error message immediately, then proceed
to shut down the server, which then prints a succint "Error:
Initialization raised an error" message.
It can be easy to overlook the error context and conclude that
there is none.
This commit will now re-display the error message at the bottom,
so that it is printed out twice.
For example:
```
./target/debug/kumod --policy /tmp/bad.lua
2023-08-31T17:20:46.569685Z INFO localset-0 kumo_server_common::http_server: http listener on 0.0.0.0:8000
2023-08-31T17:20:46.570330Z INFO localset-0 kumo_server_common::http_server: https listener on 0.0.0.0:8001
2023-08-31T17:20:46.570761Z INFO localset-0 kumod::smtp_server: smtp listener on 0.0.0.0:2025
2023-08-31T17:20:46.621327Z ERROR localset-0 kumo_server_common::start: problem initializing: callback error
stack traceback:
[C]: in function 'kumo.on'
[string "/tmp/bad.lua"]:86: in function <[string "/tmp/bad.lua"]:6>
caused by: Attempting to register an event handler via `kumo.on('get_listener_domain', ...)` from within the event handler 'init'. You must move your event handler registration so that it is setup directly when the policy is loaded in order for it to consistently trigger and handle events.
2023-08-31T17:20:46.621437Z INFO localset-0 kumo_server_common::start: initialization complete
2023-08-31T17:20:46.621581Z INFO localset-0 kumod::smtp_server: smtp listener on 0.0.0.0:2025 -> stopping
2023-08-31T17:20:46.622242Z INFO main kumo_server_common::start: Shutdown completed OK!
Error: Initialization raised an error: callback error
stack traceback:
[C]: in function 'kumo.on'
[string "/tmp/bad.lua"]:86: in function <[string "/tmp/bad.lua"]:6>
caused by: Attempting to register an event handler via `kumo.on('get_listener_domain', ...)` from within the event handler 'init'. You must move your event handler registration so that it is setup directly when the policy is loaded in order for it to consistently trigger and handle events.
```
This commit is contained in:
@@ -36,18 +36,19 @@ impl<'a> StartConfig<'a> {
|
||||
|
||||
let init_handle = rt_spawn("initialize".to_string(), move || {
|
||||
Ok(async move {
|
||||
let mut ok = true;
|
||||
let mut error = None;
|
||||
let init_future = (perform_init)();
|
||||
if let Err(err) = init_future.await {
|
||||
tracing::error!("problem initializing: {err:#}");
|
||||
let err = format!("{err:#}");
|
||||
tracing::error!("problem initializing: {err}");
|
||||
LifeCycle::request_shutdown().await;
|
||||
ok = false;
|
||||
error.replace(err);
|
||||
}
|
||||
// This log line is depended upon by the integration
|
||||
// test harness. Do not change or remove it without
|
||||
// making appropriate adjustments over there!
|
||||
tracing::info!("initialization complete");
|
||||
ok
|
||||
error
|
||||
})
|
||||
})
|
||||
.await?;
|
||||
@@ -60,8 +61,8 @@ impl<'a> StartConfig<'a> {
|
||||
|
||||
tracing::info!("Shutdown completed OK!");
|
||||
|
||||
if !init_handle.await? {
|
||||
anyhow::bail!("Initialization raised an error");
|
||||
if let Some(error) = init_handle.await? {
|
||||
anyhow::bail!("Initialization raised an error: {error}");
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user