error: Move errors to a separate module
For some reason, using the `thiserror::Error` derive macro causes the syntax highlighting to fail for the rest of the code in the file, at least in Neovim. Having all the errors in one module will consolidate this effect to that one file.
This commit is contained in:
7
src/error.rs
Normal file
7
src/error.rs
Normal file
@@ -0,0 +1,7 @@
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
pub enum InitError {
|
||||
#[error("Meilisearch error: {0}")]
|
||||
Meilisearch(#[from] crate::meilisearch::Error),
|
||||
#[error("Failed to load JWT secret: {0}")]
|
||||
LoadSecret(std::io::Error),
|
||||
}
|
||||
10
src/lib.rs
10
src/lib.rs
@@ -1,5 +1,6 @@
|
||||
pub mod auth;
|
||||
pub mod config;
|
||||
mod error;
|
||||
pub mod meilisearch;
|
||||
pub mod page;
|
||||
|
||||
@@ -9,20 +10,13 @@ use rocket::Rocket;
|
||||
use tracing::error;
|
||||
|
||||
use config::Config;
|
||||
pub use error::InitError;
|
||||
|
||||
pub struct Context {
|
||||
client: MeilisearchClient,
|
||||
jwt_secret: Vec<u8>,
|
||||
}
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
pub enum InitError {
|
||||
#[error("Meilisearch error: {0}")]
|
||||
Meilisearch(#[from] meilisearch::Error),
|
||||
#[error("Failed to load JWT secret: {0}")]
|
||||
LoadSecret(std::io::Error),
|
||||
}
|
||||
|
||||
impl Context {
|
||||
pub fn init(config: &Config) -> Result<Self, InitError> {
|
||||
let client = MeilisearchClient::try_from(config)?;
|
||||
|
||||
Reference in New Issue
Block a user