Sync everything before trying sqlx

This commit is contained in:
Daniel Flanagan 2023-11-14 11:02:58 -06:00
parent 05a62bb456
commit bfc5a6f90d
Signed by: lytedev
GPG key ID: 5B2020A0F9921EF4
8 changed files with 103 additions and 13 deletions

2
.cargo/config.toml Normal file
View file

@ -0,0 +1,2 @@
[env]
RUST_BACKTRACE = "1"

60
Cargo.lock generated
View file

@ -266,6 +266,33 @@ dependencies = [
"inout", "inout",
] ]
[[package]]
name = "color-eyre"
version = "0.6.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a667583cca8c4f8436db8de46ea8233c42a7d9ae424a82d338f2e4675229204"
dependencies = [
"backtrace",
"color-spantrace",
"eyre",
"indenter",
"once_cell",
"owo-colors",
"tracing-error",
]
[[package]]
name = "color-spantrace"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1ba75b3d9449ecdccb27ecbc479fdc0b87fa2dd43d2f8298f9bf0e59aacc8dce"
dependencies = [
"once_cell",
"owo-colors",
"tracing-core",
"tracing-error",
]
[[package]] [[package]]
name = "cookie" name = "cookie"
version = "0.18.0" version = "0.18.0"
@ -444,6 +471,16 @@ version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5"
[[package]]
name = "eyre"
version = "0.6.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4c2b6b5a29c02cdc822728b7d7b8ae1bab3e3b05d44522770ddd49722eeac7eb"
dependencies = [
"indenter",
"once_cell",
]
[[package]] [[package]]
name = "filetime" name = "filetime"
version = "0.2.22" version = "0.2.22"
@ -670,6 +707,12 @@ dependencies = [
"want", "want",
] ]
[[package]]
name = "indenter"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ce23b50ad8242c51a442f3ff322d56b02f08852c77e4c0b4d3fd684abc89c683"
[[package]] [[package]]
name = "indexmap" name = "indexmap"
version = "2.1.0" version = "2.1.0"
@ -783,6 +826,7 @@ dependencies = [
"axum-macros", "axum-macros",
"axum_csrf", "axum_csrf",
"base64", "base64",
"color-eyre",
"cookie", "cookie",
"deadpool", "deadpool",
"deadpool-diesel", "deadpool-diesel",
@ -966,6 +1010,12 @@ version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39"
[[package]]
name = "owo-colors"
version = "3.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f"
[[package]] [[package]]
name = "parking_lot" name = "parking_lot"
version = "0.12.1" version = "0.12.1"
@ -1633,6 +1683,16 @@ dependencies = [
"valuable", "valuable",
] ]
[[package]]
name = "tracing-error"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d686ec1c0f384b1277f097b2f279a2ecc11afe8c133c1aabf036a27cb4cd206e"
dependencies = [
"tracing",
"tracing-subscriber",
]
[[package]] [[package]]
name = "tracing-log" name = "tracing-log"
version = "0.1.4" version = "0.1.4"

View file

@ -32,4 +32,10 @@ tower-livereload = "0.8.2"
argon2 = { version = "0.5.2", features = ["std"] } argon2 = { version = "0.5.2", features = ["std"] }
thiserror = "1.0.50" thiserror = "1.0.50"
axum-macros = "0.3.8" axum-macros = "0.3.8"
color-eyre = "0.6.2"
# color-eyre
# irust
# bacon
# sqlx (sea orm?)
# poem-openapi?

View file

@ -50,6 +50,7 @@
rustfmt rustfmt
rustPackages.clippy rustPackages.clippy
rustPackages.bacon
rust-analyzer rust-analyzer
nodePackages_latest.vscode-langservers-extracted nodePackages_latest.vscode-langservers-extracted

View file

@ -1,7 +1,7 @@
use crate::{instrumentation, router, server::listen}; use crate::{instrumentation, router, server::listen};
pub async fn run() -> Result<(), anyhow::Error> { pub async fn run() -> Result<(), anyhow::Error> {
instrumentation::setup_trace_logger(); instrumentation::init();
listen(router::new().await?).await; listen(router::new().await?).await;
Ok(()) Ok(())
} }

View file

@ -1,9 +1,13 @@
use std::fmt::Display;
use axum::{ use axum::{
http::StatusCode, http::StatusCode,
response::{IntoResponse, Response}, response::{IntoResponse, Response},
}; };
use thiserror::Error;
pub struct AppError(anyhow::Error); #[derive(Error, Debug)]
pub struct AppError(#[from] anyhow::Error);
impl IntoResponse for AppError { impl IntoResponse for AppError {
fn into_response(self) -> Response { fn into_response(self) -> Response {
@ -15,11 +19,8 @@ impl IntoResponse for AppError {
} }
} }
impl<E> From<E> for AppError impl Display for AppError {
where fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
E: Into<anyhow::Error>, f.write_fmt(format!("app error"))
{
fn from(err: E) -> Self {
Self(err.into())
} }
} }

View file

@ -1,6 +1,11 @@
use tracing::{instrument, trace}; use tracing::{instrument, trace};
use tracing_subscriber::{filter::LevelFilter, EnvFilter}; use tracing_subscriber::{filter::LevelFilter, EnvFilter};
pub fn init() {
color_eyre::install();
setup_trace_logger();
}
#[instrument] #[instrument]
pub fn setup_trace_logger() { pub fn setup_trace_logger() {
let filter = EnvFilter::builder() let filter = EnvFilter::builder()

View file

@ -1,11 +1,15 @@
use std::{error::Error, sync::Arc};
use axum::{ use axum::{
extract::State, extract::State,
response::{Html, IntoResponse}, response::{Html, IntoResponse},
}; };
use axum_csrf::CsrfToken; use axum_csrf::CsrfToken;
use axum_macros::debug_handler; use axum_macros::debug_handler;
use deadpool_diesel::InteractError;
use diesel::{QueryDsl, RunQueryDsl, SelectableHelper}; use diesel::{QueryDsl, RunQueryDsl, SelectableHelper};
use maud::html; use maud::html;
use thiserror::Error;
use tracing::instrument; use tracing::instrument;
use crate::{ use crate::{
@ -98,21 +102,32 @@ pub async fn login(csrf: CsrfToken) -> impl IntoResponse {
.into_response() .into_response()
} }
#[derive(Error, Debug)]
enum AllUsersError {
#[error("other application error")]
App(#[from] AppError),
#[error("failed to retrieve users")]
DB(#[from] InteractError),
}
#[debug_handler] #[debug_handler]
pub async fn all_users( pub async fn all_users(
State(state): State<crate::state::State>, State(state): State<crate::state::State>,
) -> Result<impl IntoResponse, AppError> { ) -> Result<Html<String>, AllUsersError> {
use crate::schema::users::dsl::*; use crate::schema::users::dsl::*;
let conn = state.database.pool.get().await?; let conn = state.database.pool.get().await?;
let cc = |c| { let cc = |c| -> Vec<User> {
users users
.select(User::as_select()) .select(User::as_select())
.load(c) .load(c)
.expect("error loading users") .expect("error loading users")
}; };
let all_users = conn.interact(cc).await?; let all_users: Vec<User> = match conn.interact(cc).await {
Ok(u) => u,
Err(e) => return Err(("failed to retrieve users")),
};
// @if let Some(name) = u.name { // @if let Some(name) = u.name {
// name // name
@ -125,9 +140,9 @@ pub async fn all_users(
main class="prose" { main class="prose" {
h1 { "Users" } h1 { "Users" }
ul { ul {
@for u in &all_users { @for u in all_users {
li { li {
(u.username) (u)
"(" "("
")" ")"
} }