Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use anyhow in entrypoint #19

Merged
merged 1 commit into from
Dec 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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