Skip to content

Commit c76610a

Browse files
committed
remove success message on error
1 parent c335d2a commit c76610a

File tree

2 files changed

+36
-43
lines changed

2 files changed

+36
-43
lines changed

src/main.rs

Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
use std::fmt::Write;
2-
31
use sqlpage::{
4-
app_config::{self, AppConfig},
2+
app_config,
53
webserver::{self, Database},
64
AppState,
75
};
@@ -21,41 +19,7 @@ async fn start() -> anyhow::Result<()> {
2119
webserver::database::migrations::apply(&app_config, &db).await?;
2220
let state = AppState::init_with_db(&app_config, db).await?;
2321
log::debug!("Starting server...");
24-
let (r, _) = tokio::join!(
25-
webserver::http::run_server(&app_config, state),
26-
log_welcome_message(&app_config)
27-
);
28-
r
29-
}
30-
31-
async fn log_welcome_message(config: &AppConfig) {
32-
let address_message = if let Some(unix_socket) = &config.unix_socket {
33-
format!("unix socket {unix_socket:?}")
34-
} else if let Some(domain) = &config.https_domain {
35-
format!("https://{}", domain)
36-
} else {
37-
let listen_on = config.listen_on();
38-
let mut msg = format!("{listen_on}");
39-
if listen_on.ip().is_unspecified() {
40-
// let the user know the service is publicly accessible
41-
write!(
42-
msg,
43-
": accessible from the network, and locally on http://localhost:{}",
44-
listen_on.port()
45-
)
46-
.unwrap();
47-
}
48-
msg
49-
};
50-
51-
log::info!(
52-
"SQLPage v{} started successfully.
53-
Now listening on {}
54-
You can write your website's code in .sql files in {}",
55-
env!("CARGO_PKG_VERSION"),
56-
address_message,
57-
config.web_root.display()
58-
);
22+
webserver::http::run_server(&app_config, state).await
5923
}
6024

6125
fn init_logging() {

src/webserver/http.rs

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -597,11 +597,40 @@ pub async fn run_server(config: &AppConfig, state: AppState) -> anyhow::Result<(
597597
.map_err(|e| bind_error(e, listen_on))?;
598598
}
599599
}
600-
server
601-
.run()
602-
.await
603-
.with_context(|| "Unable to start the application")?;
604-
Ok(())
600+
601+
let (r, _) = tokio::join!(server.run(), log_welcome_message(&config));
602+
r.with_context(|| "Unable to start the application")
603+
}
604+
605+
async fn log_welcome_message(config: &AppConfig) {
606+
let address_message = if let Some(unix_socket) = &config.unix_socket {
607+
format!("unix socket {unix_socket:?}")
608+
} else if let Some(domain) = &config.https_domain {
609+
format!("https://{}", domain)
610+
} else {
611+
use std::fmt::Write;
612+
let listen_on = config.listen_on();
613+
let mut msg = format!("{listen_on}");
614+
if listen_on.ip().is_unspecified() {
615+
// let the user know the service is publicly accessible
616+
write!(
617+
msg,
618+
": accessible from the network, and locally on http://localhost:{}",
619+
listen_on.port()
620+
)
621+
.unwrap();
622+
}
623+
msg
624+
};
625+
626+
log::info!(
627+
"SQLPage v{} started successfully.
628+
Now listening on {}
629+
You can write your website's code in .sql files in {}",
630+
env!("CARGO_PKG_VERSION"),
631+
address_message,
632+
config.web_root.display()
633+
);
605634
}
606635

607636
fn bind_error(e: std::io::Error, listen_on: std::net::SocketAddr) -> anyhow::Error {

0 commit comments

Comments
 (0)