mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-23 13:24:27 +01:00
better exit on error
Update meilisearch-core/src/database.rs Co-authored-by: Clément Renault <renault.cle@gmail.com> Update meilisearch-core/src/database.rs Co-authored-by: Clément Renault <renault.cle@gmail.com>
This commit is contained in:
parent
6f0b6933e6
commit
51d7c84e73
@ -180,15 +180,15 @@ fn version_guard(path: &Path, create: bool) -> MResult<()> {
|
|||||||
let version_minor = version.next().ok_or(Error::VersionMismatch("bad VERSION file".to_string()))?;
|
let version_minor = version.next().ok_or(Error::VersionMismatch("bad VERSION file".to_string()))?;
|
||||||
|
|
||||||
if version_major != current_version_major || version_minor != current_version_minor {
|
if version_major != current_version_major || version_minor != current_version_minor {
|
||||||
return Err(Error::VersionMismatch(format!("{}.{}.XX", version_major, version_major)));
|
return Err(Error::VersionMismatch(format!("{}.{}.XX", version_major, version_minor)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(error) => {
|
Err(error) => {
|
||||||
match error.kind() {
|
match error.kind() {
|
||||||
ErrorKind::NotFound => {
|
ErrorKind::NotFound => {
|
||||||
if create {
|
if create {
|
||||||
// when no version file is found, and we've beem told to create one,
|
// when no version file is found, and we've been told to create one,
|
||||||
// create a new file wioth the current version in it.
|
// create a new file with the current version in it.
|
||||||
let mut version_file = File::create(&version_path)?;
|
let mut version_file = File::create(&version_path)?;
|
||||||
version_file.write_all(format!("{}.{}.{}",
|
version_file.write_all(format!("{}.{}.{}",
|
||||||
current_version_major,
|
current_version_major,
|
||||||
@ -196,7 +196,7 @@ fn version_guard(path: &Path, create: bool) -> MResult<()> {
|
|||||||
current_version_patch).as_bytes())?;
|
current_version_patch).as_bytes())?;
|
||||||
} else {
|
} else {
|
||||||
// when no version file is found and we were not told to create one, this
|
// when no version file is found and we were not told to create one, this
|
||||||
// means that the version is inferior to the one this feature was added.
|
// means that the version is inferior to the one this feature was added in.
|
||||||
return Err(Error::VersionMismatch(format!("<0.12.0")));
|
return Err(Error::VersionMismatch(format!("<0.12.0")));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -158,7 +158,11 @@ impl fmt::Display for Error {
|
|||||||
SchemaMissing => write!(f, "this index does not have a schema"),
|
SchemaMissing => write!(f, "this index does not have a schema"),
|
||||||
SerdeJson(e) => write!(f, "serde json error; {}", e),
|
SerdeJson(e) => write!(f, "serde json error; {}", e),
|
||||||
Serializer(e) => write!(f, "serializer error; {}", e),
|
Serializer(e) => write!(f, "serializer error; {}", e),
|
||||||
VersionMismatch(version) => write!(f, "Cannot open database, expected Meilisearch version: {}", version),
|
VersionMismatch(version) => write!(f, "Cannot open database, expected MeiliSearch engine version: {}, currrent engine version: {}.{}.{}",
|
||||||
|
version,
|
||||||
|
env!("CARGO_PKG_VERSION_MAJOR"),
|
||||||
|
env!("CARGO_PKG_VERSION_MINOR"),
|
||||||
|
env!("CARGO_PKG_VERSION_PATCH")),
|
||||||
WordIndexMissing => write!(f, "this index does not have a word index"),
|
WordIndexMissing => write!(f, "this index does not have a word index"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
|
use std::error::Error;
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use meilisearch_core::{Database, DatabaseOptions};
|
use meilisearch_core::{Database, DatabaseOptions};
|
||||||
use sha2::Digest;
|
use sha2::Digest;
|
||||||
use sysinfo::Pid;
|
use sysinfo::Pid;
|
||||||
use log::error;
|
|
||||||
|
|
||||||
use crate::index_update_callback;
|
use crate::index_update_callback;
|
||||||
use crate::option::Opt;
|
use crate::option::Opt;
|
||||||
@ -56,7 +56,7 @@ impl ApiKeys {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Data {
|
impl Data {
|
||||||
pub fn new(opt: Opt) -> Data {
|
pub fn new(opt: Opt) -> Result<Data, Box<dyn Error>> {
|
||||||
let db_path = opt.db_path.clone();
|
let db_path = opt.db_path.clone();
|
||||||
let server_pid = sysinfo::get_current_pid().unwrap();
|
let server_pid = sysinfo::get_current_pid().unwrap();
|
||||||
|
|
||||||
@ -67,13 +67,7 @@ impl Data {
|
|||||||
|
|
||||||
let http_payload_size_limit = opt.http_payload_size_limit;
|
let http_payload_size_limit = opt.http_payload_size_limit;
|
||||||
|
|
||||||
let db = match Database::open_or_create(opt.db_path, db_opt) {
|
let db = Arc::new(Database::open_or_create(opt.db_path, db_opt)?);
|
||||||
Ok(db) => Arc::new(db),
|
|
||||||
Err(e) => {
|
|
||||||
error!("{}", e);
|
|
||||||
std::process::exit(1);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut api_keys = ApiKeys {
|
let mut api_keys = ApiKeys {
|
||||||
master: opt.master_key,
|
master: opt.master_key,
|
||||||
@ -100,6 +94,6 @@ impl Data {
|
|||||||
index_update_callback(&index_uid, &callback_context, status);
|
index_update_callback(&index_uid, &callback_context, status);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
data
|
Ok(data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ async fn main() -> Result<(), MainError> {
|
|||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
}
|
}
|
||||||
|
|
||||||
let data = Data::new(opt.clone());
|
let data = Data::new(opt.clone())?;
|
||||||
|
|
||||||
if !opt.no_analytics {
|
if !opt.no_analytics {
|
||||||
let analytics_data = data.clone();
|
let analytics_data = data.clone();
|
||||||
|
@ -50,7 +50,7 @@ impl Server {
|
|||||||
..Opt::default()
|
..Opt::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
let data = Data::new(opt.clone());
|
let data = Data::new(opt.clone()).unwrap();
|
||||||
|
|
||||||
Server {
|
Server {
|
||||||
uid: uid.to_string(),
|
uid: uid.to_string(),
|
||||||
|
Loading…
Reference in New Issue
Block a user