Closes #235 - adds a new error type (#398)

error message suggests possible causes

Addressed code review 1 thread + smaller heap size
This commit is contained in:
petr-tik
2018-08-29 00:26:59 +01:00
committed by Paul Masurel
parent 57e1f8ed28
commit d15efd6635
2 changed files with 27 additions and 2 deletions

View File

@@ -9,6 +9,7 @@ use schema;
use serde_json;
use std::path::PathBuf;
use std::sync::PoisonError;
use core::LOCKFILE_FILEPATH;
/// The library's failure based error enum
#[derive(Debug, Fail)]
@@ -19,6 +20,9 @@ pub enum TantivyError {
/// File already exists, this is a problem when we try to write into a new file.
#[fail(display = "file already exists: '{:?}'", _0)]
FileAlreadyExists(PathBuf),
/// Lockfile already exists
#[fail(display = "Lockfile '{:?}' already exists. Possible causes: another IndexWriter instance or panic during previous lock drop.", _0)]
LockFileAlreadyExists(PathBuf),
/// IO Error.
#[fail(display = "an IO error occurred: '{}'", _0)]
IOError(#[cause] IOError),
@@ -95,7 +99,12 @@ impl From<OpenWriteError> for TantivyError {
fn from(error: OpenWriteError) -> TantivyError {
match error {
OpenWriteError::FileAlreadyExists(filepath) => {
TantivyError::FileAlreadyExists(filepath)
let lockfile_fname = LOCKFILE_FILEPATH.to_str().unwrap();
if filepath.ends_with(lockfile_fname) {
TantivyError::LockFileAlreadyExists(filepath)
} else {
TantivyError::FileAlreadyExists(filepath)
}
}
OpenWriteError::IOError(io_error) => TantivyError::IOError(io_error),
}.into()