review changes

This commit is contained in:
marin postma 2021-06-21 13:57:32 +02:00
parent 763ee521be
commit 56686dee40
No known key found for this signature in database
GPG Key ID: 6088B7721C3E39F9
10 changed files with 24 additions and 23 deletions

View File

@ -14,9 +14,9 @@ use crate::index_controller::error::IndexControllerError;
#[derive(Debug, thiserror::Error)] #[derive(Debug, thiserror::Error)]
pub enum AuthenticationError { pub enum AuthenticationError {
#[error("You must have an authorization token")] #[error("you must have an authorization token")]
MissingAuthorizationHeader, MissingAuthorizationHeader,
#[error("Invalid API key")] #[error("invalid API key")]
InvalidToken(String), InvalidToken(String),
} }

View File

@ -3,7 +3,7 @@ use std::io::{BufRead, BufReader, Write};
use std::path::Path; use std::path::Path;
use std::sync::Arc; use std::sync::Arc;
use anyhow::Context; use anyhow::{Context, bail};
use heed::RoTxn; use heed::RoTxn;
use indexmap::IndexMap; use indexmap::IndexMap;
use milli::update::{IndexDocumentsMethod, UpdateFormat::JsonStream}; use milli::update::{IndexDocumentsMethod, UpdateFormat::JsonStream};
@ -126,7 +126,7 @@ impl Index {
match Arc::try_unwrap(index.0) { match Arc::try_unwrap(index.0) {
Ok(inner) => inner.prepare_for_closing().wait(), Ok(inner) => inner.prepare_for_closing().wait(),
Err(_) => todo!("Could not close index properly."), Err(_) => bail!("Could not close index properly."),
} }
Ok(()) Ok(())

View File

@ -9,9 +9,9 @@ pub type Result<T> = std::result::Result<T, IndexError>;
#[derive(Debug, thiserror::Error)] #[derive(Debug, thiserror::Error)]
pub enum IndexError { pub enum IndexError {
#[error("Internal error: {0}")] #[error("internal error: {0}")]
Internal(Box<dyn Error + Send + Sync + 'static>), Internal(Box<dyn Error + Send + Sync + 'static>),
#[error("Document with id {0} not found.")] #[error("document with id {0} not found.")]
DocumentNotFound(String), DocumentNotFound(String),
#[error("error with facet: {0}")] #[error("error with facet: {0}")]
Facet(#[from] FacetError), Facet(#[from] FacetError),
@ -39,7 +39,7 @@ impl ErrorCode for IndexError {
#[derive(Debug, thiserror::Error)] #[derive(Debug, thiserror::Error)]
pub enum FacetError { pub enum FacetError {
#[error("Invalid facet expression, expected {}, found: {1}", .0.join(", "))] #[error("invalid facet expression, expected {}, found: {1}", .0.join(", "))]
InvalidExpression(&'static [&'static str], Value), InvalidExpression(&'static [&'static str], Value),
} }

View File

@ -11,7 +11,7 @@ pub enum DumpActorError {
DumpAlreadyRunning, DumpAlreadyRunning,
#[error("dump `{0}` does not exist")] #[error("dump `{0}` does not exist")]
DumpDoesNotExist(String), DumpDoesNotExist(String),
#[error("Internal error: {0}")] #[error("internal error: {0}")]
Internal(Box<dyn std::error::Error + Send + Sync + 'static>), Internal(Box<dyn std::error::Error + Send + Sync + 'static>),
#[error("error while dumping uuids: {0}")] #[error("error while dumping uuids: {0}")]
UuidResolver(#[from] UuidResolverError), UuidResolver(#[from] UuidResolverError),

View File

@ -10,7 +10,7 @@ pub type Result<T> = std::result::Result<T, IndexControllerError>;
#[derive(Debug, thiserror::Error)] #[derive(Debug, thiserror::Error)]
pub enum IndexControllerError { pub enum IndexControllerError {
#[error("Missing index uid")] #[error("missing index uid")]
MissingUid, MissingUid,
#[error("index resolution error: {0}")] #[error("index resolution error: {0}")]
Uuid(#[from] UuidResolverError), Uuid(#[from] UuidResolverError),

View File

@ -10,11 +10,11 @@ pub enum IndexActorError {
IndexError(#[from] IndexError), IndexError(#[from] IndexError),
#[error("index already exists")] #[error("index already exists")]
IndexAlreadyExists, IndexAlreadyExists,
#[error("Index doesn't exists")] #[error("index doesn't exists")]
UnexistingIndex, UnexistingIndex,
#[error("Existing primary key")] #[error("existing primary key")]
ExistingPrimaryKey, ExistingPrimaryKey,
#[error("Internal Index Error: {0}")] #[error("internal Index Error: {0}")]
Internal(Box<dyn std::error::Error + Send + Sync + 'static>), Internal(Box<dyn std::error::Error + Send + Sync + 'static>),
#[error("{0}")] #[error("{0}")]
Milli(#[from] milli::Error), Milli(#[from] milli::Error),

View File

@ -330,10 +330,10 @@ impl IndexController {
pub async fn update_index( pub async fn update_index(
&self, &self,
uid: String, uid: String,
index_settings: IndexSettings, mut index_settings: IndexSettings,
) -> Result<IndexMetadata> { ) -> Result<IndexMetadata> {
if index_settings.uid.is_some() { if index_settings.uid.is_some() {
todo!("Can't change the index uid.") index_settings.uid.take();
} }
let uuid = self.uuid_resolver.get(uid.clone()).await?; let uuid = self.uuid_resolver.get(uid.clone()).await?;

View File

@ -1,6 +1,7 @@
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::time::Duration; use std::time::Duration;
use anyhow::bail;
use log::{error, info}; use log::{error, info};
use tokio::fs; use tokio::fs;
use tokio::task::spawn_blocking; use tokio::task::spawn_blocking;
@ -108,7 +109,7 @@ pub fn load_snapshot(
} }
} }
} else if db_path.as_ref().exists() && !ignore_snapshot_if_db_exists { } else if db_path.as_ref().exists() && !ignore_snapshot_if_db_exists {
todo!( bail!(
"database already exists at {:?}, try to delete it or rename it", "database already exists at {:?}, try to delete it or rename it",
db_path db_path
.as_ref() .as_ref()
@ -116,7 +117,7 @@ pub fn load_snapshot(
.unwrap_or_else(|_| db_path.as_ref().to_owned()) .unwrap_or_else(|_| db_path.as_ref().to_owned())
) )
} else if !snapshot_path.as_ref().exists() && !ignore_missing_snapshot { } else if !snapshot_path.as_ref().exists() && !ignore_missing_snapshot {
todo!( bail!(
"snapshot doesn't exist at {:?}", "snapshot doesn't exist at {:?}",
snapshot_path snapshot_path
.as_ref() .as_ref()

View File

@ -9,14 +9,14 @@ pub type Result<T> = std::result::Result<T, UpdateActorError>;
#[derive(Debug, thiserror::Error)] #[derive(Debug, thiserror::Error)]
#[allow(clippy::large_enum_variant)] #[allow(clippy::large_enum_variant)]
pub enum UpdateActorError { pub enum UpdateActorError {
#[error("Update {0} doesn't exist.")] #[error("update {0} doesn't exist.")]
UnexistingUpdate(u64), UnexistingUpdate(u64),
#[error("Internal error processing update: {0}")] #[error("internal error processing update: {0}")]
Internal(Box<dyn Error + Send + Sync + 'static>), Internal(Box<dyn Error + Send + Sync + 'static>),
#[error("error with index: {0}")] #[error("error with index: {0}")]
IndexActor(#[from] IndexActorError), IndexActor(#[from] IndexActorError),
#[error( #[error(
"Update store was shut down due to a fatal error, please check your logs for more info." "update store was shut down due to a fatal error, please check your logs for more info."
)] )]
FatalUpdateStoreError, FatalUpdateStoreError,
} }

View File

@ -4,13 +4,13 @@ pub type Result<T> = std::result::Result<T, UuidResolverError>;
#[derive(Debug, thiserror::Error)] #[derive(Debug, thiserror::Error)]
pub enum UuidResolverError { pub enum UuidResolverError {
#[error("Name already exist.")] #[error("name already exist.")]
NameAlreadyExist, NameAlreadyExist,
#[error("Index \"{0}\" doesn't exist.")] #[error("index \"{0}\" doesn't exist.")]
UnexistingIndex(String), UnexistingIndex(String),
#[error("Badly formatted index uid: {0}")] #[error("badly formatted index uid: {0}")]
BadlyFormatted(String), BadlyFormatted(String),
#[error("Internal error resolving index uid: {0}")] #[error("internal error resolving index uid: {0}")]
Internal(Box<dyn std::error::Error + Sync + Send + 'static>), Internal(Box<dyn std::error::Error + Sync + Send + 'static>),
} }