1- use anyhow:: Context as _;
1+ use anyhow:: { Context as _, bail } ;
22use bazooka_bot:: { ClapConfig , Data , SharedConfig , StartupConfig , commands_list, heartbeat} ;
33use poise:: serenity_prelude:: { ClientBuilder , GatewayIntents } ;
44use secrecy:: ExposeSecret ;
@@ -14,7 +14,7 @@ use version::version;
1414use clap:: Parser ;
1515
1616#[ tokio:: main]
17- async fn main ( ) {
17+ async fn main ( ) -> anyhow :: Result < ( ) > {
1818 tracing_subscriber:: registry ( )
1919 . with ( fmt:: layer ( ) . with_span_events ( FmtSpan :: NEW | FmtSpan :: CLOSE ) )
2020 . with (
@@ -27,14 +27,17 @@ async fn main() {
2727
2828 // Load setup values
2929 info ! ( "Loading environment variables" ) ;
30- loadenv:: load ( ) . expect ( "failed to load .env file" ) ;
30+ match loadenv:: load ( ) {
31+ Ok ( was_found) => debug ! ( ".env file was found: {was_found}" ) ,
32+ Err ( err_msg) => bail ! ( "failed to load .env file: {err_msg:?}" ) ,
33+ }
3134 let clap_config = ClapConfig :: parse ( ) ;
3235 debug ! ( "ClapConfig: {:?}" , clap_config) ;
3336
3437 let startup_config =
35- StartupConfig :: try_new ( & clap_config) . expect ( "failed to create setup config" ) ;
38+ StartupConfig :: try_new ( & clap_config) . context ( "failed to create setup config" ) ? ;
3639 let shared_config =
37- SharedConfig :: try_new ( & clap_config) . expect ( "failed to created shared_config" ) ;
40+ SharedConfig :: try_new ( & clap_config) . context ( "failed to created shared_config" ) ? ;
3841 let discord_token = clap_config. discord_token ;
3942
4043 let framework = poise:: Framework :: builder ( )
@@ -101,9 +104,10 @@ async fn main() {
101104 )
102105 . framework ( framework)
103106 . await
104- . expect ( "Error creating client" ) ;
107+ . context ( "Error creating client" ) ? ;
105108
106- if let Err ( why) = client. start ( ) . await {
107- error ! ( "Client error: {why:?}" ) ;
108- }
109+ client
110+ . start ( )
111+ . await
112+ . context ( "failed to start discord client" )
109113}
0 commit comments