Skip to content

Commit

Permalink
Merge pull request #19 from traP-jp/use-anyhow
Browse files Browse the repository at this point in the history
  • Loading branch information
zer0-star authored Dec 16, 2023
2 parents 5cfe6a2 + 6612584 commit aa13375
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions entrypoint/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ traq-bot-http.workspace = true
bot-client.path = "../bot-client"
handler.path = "../handler"
repository.path = "../repository"
anyhow = "1.0.75"
13 changes: 7 additions & 6 deletions entrypoint/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::{env, process::exit};

use anyhow::{Context, Result};
use once_cell::sync::Lazy;
use rocket::{fairing::AdHoc, http::Method, routes};
use traq_bot_http::RequestParser;
Expand All @@ -20,10 +21,10 @@ static CORS_CONFIG: Lazy<CorsConfig> = Lazy::new(|| {
});

#[tokio::main]
async fn main() -> Result<(), rocket::Error> {
async fn main() -> Result<()> {
let verification_token =
env::var("VERIFICATION_TOKEN").expect("env var VERIFICATION_TOKEN is unset");
let access_token = env::var("BOT_ACCESS_TOKEN").expect("env var BOT_ACCESS_TOKEN is unset");
env::var("VERIFICATION_TOKEN").context("env var VERIFICATION_TOKEN is unset")?;
let access_token = env::var("BOT_ACCESS_TOKEN").context("env var BOT_ACCESS_TOKEN is unset")?;
let check_auth = env::var("CHECK_AUTH")
.ok()
.and_then(|c| c.parse::<bool>().ok())
Expand All @@ -35,10 +36,10 @@ async fn main() -> Result<(), rocket::Error> {
let config = load("")
.or_else(|_| load("MYSQL_"))
.or_else(|_| load("NS_MARIADB_"))
.expect("env var config for database not found");
.context("env var config for database not found")?;
CardRepositoryImpl::connect_with_config(config)
.await
.expect("failed to connect database")
.context("failed to connect database")?
};
let migration_strategy = env::var("MIGRATION")
.ok()
Expand All @@ -47,7 +48,7 @@ async fn main() -> Result<(), rocket::Error> {
card_repository
.migrate(migration_strategy)
.await
.expect("failed white migration");
.context("failed white migration")?;
rocket::build()
.mount("/api", routes![handler::ping])
.mount("/api/cards", handler::cards::routes())
Expand Down

0 comments on commit aa13375

Please sign in to comment.