summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/channel/routes.rs8
-rw-r--r--src/error.rs8
-rw-r--r--src/events/app/events.rs11
-rw-r--r--src/events/app/mod.rs2
-rw-r--r--src/events/routes.rs4
-rw-r--r--src/events/routes/test.rs13
-rw-r--r--src/lib.rs2
-rw-r--r--src/login/routes.rs6
-rw-r--r--src/login/routes/test/login.rs4
-rw-r--r--src/login/routes/test/logout.rs6
-rw-r--r--src/repo/login/extract.rs8
-rw-r--r--src/test/fixtures/login.rs2
12 files changed, 41 insertions, 33 deletions
diff --git a/src/channel/routes.rs b/src/channel/routes.rs
index bb6cde6..f524e62 100644
--- a/src/channel/routes.rs
+++ b/src/channel/routes.rs
@@ -10,7 +10,7 @@ use super::app;
use crate::{
app::App,
clock::RequestedAt,
- error::InternalError,
+ error::Internal,
events::app::EventsError,
repo::{
channel::{self, Channel},
@@ -28,7 +28,7 @@ pub fn router() -> Router<App> {
.route("/api/channels/:channel", post(on_send))
}
-async fn list(State(app): State<App>, _: Login) -> Result<Channels, InternalError> {
+async fn list(State(app): State<App>, _: Login) -> Result<Channels, Internal> {
let channels = app.channels().all().await?;
let response = Channels(channels);
@@ -73,7 +73,7 @@ impl IntoResponse for CreateError {
duplicate @ app::CreateError::DuplicateName(_) => {
(StatusCode::BAD_REQUEST, duplicate.to_string()).into_response()
}
- other => InternalError::from(other).into_response(),
+ other => Internal::from(other).into_response(),
}
}
}
@@ -109,7 +109,7 @@ impl IntoResponse for ErrorResponse {
not_found @ EventsError::ChannelNotFound(_) => {
(StatusCode::NOT_FOUND, not_found.to_string()).into_response()
}
- other => InternalError::from(other).into_response(),
+ other => Internal::from(other).into_response(),
}
}
}
diff --git a/src/error.rs b/src/error.rs
index ffc90e9..6e797b4 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -16,9 +16,9 @@ type BoxedError = Box<dyn error::Error + Send + Sync>;
// Returns a 500 Internal Server Error to the client. Meant to be used via the
// `?` operator; _does not_ return the originating error to the client.
#[derive(Debug)]
-pub struct InternalError(Id, BoxedError);
+pub struct Internal(Id, BoxedError);
-impl<E> From<E> for InternalError
+impl<E> From<E> for Internal
where
E: Into<BoxedError>,
{
@@ -28,13 +28,13 @@ where
}
}
-impl IntoResponse for InternalError {
+impl IntoResponse for Internal {
fn into_response(self) -> Response {
let Self(id, error) = self;
eprintln!("hi: [{id}] {error}");
(
StatusCode::INTERNAL_SERVER_ERROR,
- format!("internal server error\nerror id: {}", id),
+ format!("internal server error\nerror id: {id}"),
)
.into_response()
}
diff --git a/src/events/app/events.rs b/src/events/app/events.rs
index a8814c9..8b76994 100644
--- a/src/events/app/events.rs
+++ b/src/events/app/events.rs
@@ -9,7 +9,10 @@ use sqlx::sqlite::SqlitePool;
use super::Broadcaster;
use crate::{
clock::DateTime,
- events::repo::broadcast::{self, Provider as _},
+ events::{
+ app::EventsError,
+ repo::broadcast::{self, Provider as _},
+ },
repo::{
channel::{self, Provider as _},
error::NotFound as _,
@@ -33,7 +36,7 @@ impl<'a> Events<'a> {
channel: &channel::Id,
body: &str,
sent_at: &DateTime,
- ) -> Result<broadcast::Message, EventsError> {
+ ) -> Result<broadcast::Message, Error> {
let mut tx = self.db.begin().await?;
let channel = tx
.channels()
@@ -55,7 +58,7 @@ impl<'a> Events<'a> {
channel: &channel::Id,
subscribed_at: &DateTime,
resume_at: Option<broadcast::Sequence>,
- ) -> Result<impl Stream<Item = broadcast::Message> + std::fmt::Debug, EventsError> {
+ ) -> Result<impl Stream<Item = broadcast::Message> + std::fmt::Debug, Error> {
// Somewhat arbitrarily, expire after 90 days.
let expire_at = subscribed_at.to_owned() - TimeDelta::days(90);
@@ -130,7 +133,7 @@ impl<'a> Events<'a> {
}
#[derive(Debug, thiserror::Error)]
-pub enum EventsError {
+pub enum Error {
#[error("channel {0} not found")]
ChannelNotFound(channel::Id),
#[error(transparent)]
diff --git a/src/events/app/mod.rs b/src/events/app/mod.rs
index 03a7da2..f364e00 100644
--- a/src/events/app/mod.rs
+++ b/src/events/app/mod.rs
@@ -2,4 +2,4 @@ mod broadcaster;
mod events;
pub use self::broadcaster::Broadcaster;
-pub use self::events::{Events, EventsError};
+pub use self::events::{Error as EventsError, Events};
diff --git a/src/events/routes.rs b/src/events/routes.rs
index 5181370..d901f9b 100644
--- a/src/events/routes.rs
+++ b/src/events/routes.rs
@@ -20,7 +20,7 @@ use super::{extract::LastEventId, repo::broadcast};
use crate::{
app::App,
clock::RequestedAt,
- error::InternalError,
+ error::Internal,
events::app::EventsError,
repo::{channel, login::Login},
};
@@ -121,7 +121,7 @@ impl IntoResponse for ErrorResponse {
not_found @ EventsError::ChannelNotFound(_) => {
(StatusCode::NOT_FOUND, not_found.to_string()).into_response()
}
- other => InternalError::from(other).into_response(),
+ other => Internal::from(other).into_response(),
}
}
}
diff --git a/src/events/routes/test.rs b/src/events/routes/test.rs
index d3f3fd6..a3f5519 100644
--- a/src/events/routes/test.rs
+++ b/src/events/routes/test.rs
@@ -111,18 +111,19 @@ async fn excludes_other_channels() {
// Set up the environment
let app = fixtures::scratch_app().await;
- let subscribed = fixtures::channel::create(&app).await;
- let unsubscribed = fixtures::channel::create(&app).await;
+ let subscribed_channel = fixtures::channel::create(&app).await;
+ let unsubscribed_channel = fixtures::channel::create(&app).await;
let sender = fixtures::login::create(&app).await;
- let message = fixtures::message::send(&app, &sender, &subscribed, &fixtures::now()).await;
- fixtures::message::send(&app, &sender, &unsubscribed, &fixtures::now()).await;
+ let message =
+ fixtures::message::send(&app, &sender, &subscribed_channel, &fixtures::now()).await;
+ fixtures::message::send(&app, &sender, &unsubscribed_channel, &fixtures::now()).await;
// Call the endpoint
let subscriber = fixtures::login::create(&app).await;
let subscribed_at = fixtures::now();
let query = routes::EventsQuery {
- channels: [subscribed.id.clone()].into(),
+ channels: [subscribed_channel.id.clone()].into(),
};
let routes::Events(mut events) =
routes::events(State(app), subscribed_at, subscriber, None, Query(query))
@@ -137,7 +138,7 @@ async fn excludes_other_channels() {
.await
.expect("delivered at least one message");
- assert_eq!(subscribed.id, event.channel);
+ assert_eq!(subscribed_channel.id, event.channel);
assert_eq!(message, event.message);
}
diff --git a/src/lib.rs b/src/lib.rs
index 9071e51..f731e57 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,4 +1,6 @@
//! `hi` - a web-based, self-hosted chat system.
+#![warn(clippy::all)]
+#![warn(clippy::pedantic)]
mod app;
mod channel;
diff --git a/src/login/routes.rs b/src/login/routes.rs
index 06e5853..31a68d0 100644
--- a/src/login/routes.rs
+++ b/src/login/routes.rs
@@ -6,7 +6,7 @@ use axum::{
Router,
};
-use crate::{app::App, clock::RequestedAt, error::InternalError, repo::login::Login};
+use crate::{app::App, clock::RequestedAt, error::Internal, repo::login::Login};
use super::{app, extract::IdentityToken};
@@ -66,7 +66,7 @@ impl IntoResponse for LoginError {
app::LoginError::Rejected => {
(StatusCode::UNAUTHORIZED, "invalid name or password").into_response()
}
- other => InternalError::from(other).into_response(),
+ other => Internal::from(other).into_response(),
}
}
}
@@ -99,7 +99,7 @@ impl IntoResponse for LogoutError {
error @ app::ValidateError::InvalidToken => {
(StatusCode::UNAUTHORIZED, error.to_string()).into_response()
}
- other => InternalError::from(other).into_response(),
+ other => Internal::from(other).into_response(),
}
}
}
diff --git a/src/login/routes/test/login.rs b/src/login/routes/test/login.rs
index 4fa491a..185239a 100644
--- a/src/login/routes/test/login.rs
+++ b/src/login/routes/test/login.rs
@@ -50,7 +50,7 @@ async fn existing_identity() {
// Set up the environment
let app = fixtures::scratch_app().await;
- let (name, password) = fixtures::login::create_for_login(&app).await;
+ let (name, password) = fixtures::login::create_with_password(&app).await;
// Call the endpoint
@@ -112,7 +112,7 @@ async fn token_expires() {
// Set up the environment
let app = fixtures::scratch_app().await;
- let (name, password) = fixtures::login::create_for_login(&app).await;
+ let (name, password) = fixtures::login::create_with_password(&app).await;
// Call the endpoint
diff --git a/src/login/routes/test/logout.rs b/src/login/routes/test/logout.rs
index 003bc8e..63b5727 100644
--- a/src/login/routes/test/logout.rs
+++ b/src/login/routes/test/logout.rs
@@ -14,7 +14,7 @@ async fn successful() {
let app = fixtures::scratch_app().await;
let now = fixtures::now();
- let login = fixtures::login::create_for_login(&app).await;
+ let login = fixtures::login::create_with_password(&app).await;
let identity = fixtures::identity::logged_in(&app, &login, &now).await;
let secret = fixtures::identity::secret(&identity);
@@ -42,7 +42,9 @@ async fn successful() {
.expect_err("secret is invalid");
match error {
app::ValidateError::InvalidToken => (), // should be invalid
- other => panic!("expected ValidateError::InvalidToken, got {other:#}"),
+ other @ app::ValidateError::DatabaseError(_) => {
+ panic!("expected ValidateError::InvalidToken, got {other:#}")
+ }
}
}
diff --git a/src/repo/login/extract.rs b/src/repo/login/extract.rs
index e808f4b..92eb516 100644
--- a/src/repo/login/extract.rs
+++ b/src/repo/login/extract.rs
@@ -8,13 +8,13 @@ use super::Login;
use crate::{
app::App,
clock::RequestedAt,
- error::InternalError,
+ error::Internal,
login::{app::ValidateError, extract::IdentityToken},
};
#[async_trait::async_trait]
impl FromRequestParts<App> for Login {
- type Rejection = LoginError<InternalError>;
+ type Rejection = LoginError<Internal>;
async fn from_request_parts(parts: &mut Parts, state: &App) -> Result<Self, Self::Rejection> {
// After Rust 1.82 (and #[feature(min_exhaustive_patterns)] lands on
@@ -52,9 +52,9 @@ where
}
}
-impl<E> From<E> for LoginError<InternalError>
+impl<E> From<E> for LoginError<Internal>
where
- E: Into<InternalError>,
+ E: Into<Internal>,
{
fn from(err: E) -> Self {
Self::Failure(err.into())
diff --git a/src/test/fixtures/login.rs b/src/test/fixtures/login.rs
index b2a4292..f1e4b15 100644
--- a/src/test/fixtures/login.rs
+++ b/src/test/fixtures/login.rs
@@ -6,7 +6,7 @@ use crate::{
repo::login::{self, Login},
};
-pub async fn create_for_login(app: &App) -> (String, String) {
+pub async fn create_with_password(app: &App) -> (String, String) {
let (name, password) = propose();
app.logins()
.create(&name, &password)