pub struct ANNError { /* private fields */ }Expand description
Common error type shared through DiskANN.
This type disambiguates the runtime origin of errors using the kind() enum. Third
party implementations of DiskANN plugin types like provider can use kind() and the
downcasting API to throw custom errors from low in the callstack and retrieve those
errors higher in the stack.
use diskann::{ANNError, ANNErrorKind, error::ErrorContext};
use thiserror::Error;
// A custom error type used by a third-party.
#[derive(Debug, Error)]
#[error("custom error: {0}")]
struct CustomError(usize);
// A low-level function that returns an error.
fn errors() -> Result<(), ANNError> {
Err(ANNError::new(ANNErrorKind::Tagged(100), CustomError(42)))
}
// A function that propagates an error, adding context.
fn propagates_with_context() -> Result<(), ANNError> {
errors().context("propagated")
}
// Call a function that returns a contextual error.
let err = propagates_with_context().unwrap_err();
// The formatted error will contain the base error and all contexts.
let message = err.to_string();
assert!(message.contains("custom error: 42"));
assert!(message.contains("propagated"));
// If we retrieve the `ANNErrorKind`, we can recognize that it belongs to a third-party
// plugin.
assert_eq!(err.kind(), ANNErrorKind::Tagged(100));
// If we know the concrete error type, we can downcast the error.
let downcasted = err.downcast_ref::<CustomError>().unwrap();
assert_eq!(downcasted.0, 42);§Backtraces
Backtraces will be obtained upon the first construction of an ANNError if the
environment variable RUST_BACKTRACE=1 is set.
Backtrace collection adds a time overhead to error collection.
§Legacy API
The log_* prefixed constructors exist to maintain compatibility with an earlier
iteration of this struct. These constructors set an internal ANNErrorKind and have
the side effect of logging the constructed object at an Error level.
The log records associated with these messages contain the following keyed metadata:
- “diskann.file” (&str) - The file of the constructor’s caller.
- “diskann.line” (&str) - The line within the file of the constructor’s caller.
This can lead to double logging as errors are logged upon creation, and the logged again upon reaching the top level.
§Properties
ANNError has the following properties to support efficiency:
std::mem::size_of::<ANNError>() == 16: The struct is 16 bytes. This allows it to be returned in registers rather than on the stack.std::mem::size_of::<Option<ANNError>>() == 16: The struct can use Rust’s niche optimization.
Implementations§
Source§impl ANNError
impl ANNError
Sourcepub fn new<E>(kind: ANNErrorKind, err: E) -> Self
pub fn new<E>(kind: ANNErrorKind, err: E) -> Self
Construct a new ANNError encapsulating err.
Errors constructed this way can be retrieved using downcasting.
use diskann::{ANNError, ANNErrorKind};
use std::env::VarError;
let err = ANNError::new(
ANNErrorKind::IndexError,
VarError::NotPresent,
);
let retrieved: VarError = err.downcast::<VarError>().unwrap();§Attributes
-
track_caller: Internally, the typeerris embedded inside aLocatedstruct, recording the file and line of creation. The[track_caller]attribute allows for precise recording of the caller. -
inline(never): To keep the happy-path cost as minimal as possible, this function is marked as[inline(never)]to outline error handling code.
Sourcepub fn opaque<E>(err: E) -> Self
pub fn opaque<E>(err: E) -> Self
Construct a new ANNError encapsulating err tagged with ANNErrorKind::Opaque.
Errors constructed this way can be retrieved using downcasting.
use diskann::{ANNError, ANNErrorKind};
use std::env::VarError;
let err = ANNError::opaque(VarError::NotPresent);
assert_eq!(err.kind(), ANNErrorKind::Opaque);
let retrieved: VarError = err.downcast::<VarError>().unwrap();§Attributes
-
track_caller: Internally, the typeerris embedded inside aLocatedstruct, recording the file and line of creation. The[track_caller]attribute allows for precise recording of the caller. -
inline(never): To keep the happy-path cost as minimal as possible, this function is marked as[inline(never)]to outline error handling code.
Sourcepub fn message<D>(kind: ANNErrorKind, display: D) -> Self
pub fn message<D>(kind: ANNErrorKind, display: D) -> Self
Construct a new ANNError with the provided error message.
§Note
Errors constructed this way are not necessarily recoverable by using the downcasting API.
§Attributes
-
track_caller: Internally, the typeerris embeded inside aLocatedstruct, recording the file and line of creation. The[track_caller]attribute allows for precise recording of the caller. -
inline(never): To keep the happy-path cost as minimal as possible, this function is marked as[inline(never)]to outline error handling code.
Sourcepub fn downcast<E>(self) -> Result<E, Self>
pub fn downcast<E>(self) -> Result<E, Self>
Attempt to downcast the error object to a concrete type.
Sourcepub fn downcast_ref<E>(&self) -> Option<&E>
pub fn downcast_ref<E>(&self) -> Option<&E>
Attempt to downcast the error object by reference.
Sourcepub fn downcast_mut<E>(&mut self) -> Option<&mut E>
pub fn downcast_mut<E>(&mut self) -> Option<&mut E>
Attempt to downcast the error object by reference.
Sourcepub fn kind(&self) -> ANNErrorKind
pub fn kind(&self) -> ANNErrorKind
Return the kind of the originally constructed error.
Sourcepub fn log_index_error<D: Display>(err: D) -> Self
pub fn log_index_error<D: Display>(err: D) -> Self
Create, log and return IndexError
Sourcepub fn log_file_handle_error<D: Display>(err: D) -> Self
pub fn log_file_handle_error<D: Display>(err: D) -> Self
Create, log and return FileHandleError
Sourcepub fn log_file_not_found_error(err: String) -> Self
pub fn log_file_not_found_error(err: String) -> Self
Create, log and return FileNotFoundError
Sourcepub fn log_ground_truth_error(err: String) -> Self
pub fn log_ground_truth_error(err: String) -> Self
Create, log and return GroundTruthError
Sourcepub fn log_index_config_error(parameter: String, err: String) -> Self
pub fn log_index_config_error(parameter: String, err: String) -> Self
Create, log and return IndexConfigError
Sourcepub fn log_try_from_int_error(err: TryFromIntError) -> Self
pub fn log_try_from_int_error(err: TryFromIntError) -> Self
Create, log and return TryFromIntError
Sourcepub fn log_io_error(err: Error) -> Self
pub fn log_io_error(err: Error) -> Self
Create, log and return IOError
Sourcepub fn log_io_send_error<T: Send + Sync + 'static>(err: SendError<T>) -> Self
pub fn log_io_send_error<T: Send + Sync + 'static>(err: SendError<T>) -> Self
Create, log and return IOSendError
Sourcepub fn log_disk_io_request_alignment_error(err: String) -> Self
pub fn log_disk_io_request_alignment_error(err: String) -> Self
Create, log and return DiskIOAlignmentError
Sourcepub fn log_mem_alloc_layout_error(err: LayoutError) -> Self
pub fn log_mem_alloc_layout_error(err: LayoutError) -> Self
Create, log and return IOError
Sourcepub fn log_lock_poison_error(err: String) -> Self
pub fn log_lock_poison_error(err: String) -> Self
Create, log and return LockPoisonError
Sourcepub fn log_pq_error<D: Display>(err: D) -> Self
pub fn log_pq_error<D: Display>(err: D) -> Self
Create, log and return PQError
Sourcepub fn log_sq_error<E>(err: E) -> Self
pub fn log_sq_error<E>(err: E) -> Self
Create, log and return SQError
Sourcepub fn log_kmeans_error(err: String) -> Self
pub fn log_kmeans_error(err: String) -> Self
Create, log and return KMeansError
Sourcepub fn log_push_error<E>(err: E) -> Self
pub fn log_push_error<E>(err: E) -> Self
Create, log and return KMeansError
Sourcepub fn log_try_from_slice_error(err: TryFromSliceError) -> Self
pub fn log_try_from_slice_error(err: TryFromSliceError) -> Self
Create, log and return TryFromSliceError
Sourcepub fn log_serde_error<D>(operation: String, err: D) -> Selfwhere
D: Display,
pub fn log_serde_error<D>(operation: String, err: D) -> Selfwhere
D: Display,
Create, log and return Serde error.
Sourcepub fn log_get_vertex_data_error(vertex_id: String, data_type: String) -> Self
pub fn log_get_vertex_data_error(vertex_id: String, data_type: String) -> Self
Create, log and return get vertex data error.
Sourcepub fn log_parse_slice_error(
parsing_source: String,
parsing_target: String,
err: String,
) -> Self
pub fn log_parse_slice_error( parsing_source: String, parsing_target: String, err: String, ) -> Self
Create, log and return parse slice error.
pub fn log_thread_pool_error(err: String) -> Self
pub fn log_invalid_operation_error(err: String) -> Self
pub fn log_async_error<D: Display>(err: D) -> Self
pub fn log_async_index_error<D: Display>(err: D) -> Self
pub fn log_async_shutdown_error<D: Display>(err: D) -> Self
pub fn log_async_runtime_error(err: String) -> Self
pub fn log_dimension_mismatch_error(err: String) -> Self
pub fn log_paged_search_error(err: String) -> Self
pub fn log_profiler_error(err: String) -> Self
pub fn log_pq_schema_registration_error<T>(err: T) -> Selfwhere
T: Display,
pub fn log_invalid_file_format<T>(err: T) -> Selfwhere
T: Display,
pub fn log_build_interrupted<T>(err: T) -> Selfwhere
T: Display,
Trait Implementations§
Source§impl Error for ANNError
impl Error for ANNError
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()
Source§impl From<ConfigError> for ANNError
impl From<ConfigError> for ANNError
Source§fn from(error: ConfigError) -> Self
fn from(error: ConfigError) -> Self
Source§impl<const INT_TO_ID: bool, FromType, ToType> From<IdConversionError<INT_TO_ID, FromType, ToType>> for ANNError
Allow conversion to ANNError for error propagation.
impl<const INT_TO_ID: bool, FromType, ToType> From<IdConversionError<INT_TO_ID, FromType, ToType>> for ANNError
Allow conversion to ANNError for error propagation.
Source§fn from(err: IdConversionError<INT_TO_ID, FromType, ToType>) -> Self
fn from(err: IdConversionError<INT_TO_ID, FromType, ToType>) -> Self
Source§impl From<Infallible> for ANNError
impl From<Infallible> for ANNError
Source§fn from(_: Infallible) -> Self
fn from(_: Infallible) -> Self
Source§impl From<Infallible> for ANNError
impl From<Infallible> for ANNError
Source§fn from(_: Infallible) -> Self
fn from(_: Infallible) -> Self
Source§impl From<KnnSearchError> for ANNError
impl From<KnnSearchError> for ANNError
Source§fn from(err: KnnSearchError) -> Self
fn from(err: KnnSearchError) -> Self
Source§impl From<LayoutError> for ANNError
impl From<LayoutError> for ANNError
Source§fn from(err: LayoutError) -> Self
fn from(err: LayoutError) -> Self
Source§impl<T, U> From<MetadataError<T, U>> for ANNError
impl<T, U> From<MetadataError<T, U>> for ANNError
Source§fn from(err: MetadataError<T, U>) -> Self
fn from(err: MetadataError<T, U>) -> Self
Source§impl From<NativeTypeLengthError> for ANNError
impl From<NativeTypeLengthError> for ANNError
Source§fn from(err: NativeTypeLengthError) -> ANNError
fn from(err: NativeTypeLengthError) -> ANNError
Source§impl From<PartitionError> for ANNError
impl From<PartitionError> for ANNError
Source§fn from(err: PartitionError) -> Self
fn from(err: PartitionError) -> Self
Source§impl From<RangeSearchError> for ANNError
impl From<RangeSearchError> for ANNError
Source§fn from(err: RangeSearchError) -> Self
fn from(err: RangeSearchError) -> Self
Source§impl From<ReadBinError> for ANNError
impl From<ReadBinError> for ANNError
Source§fn from(err: ReadBinError) -> Self
fn from(err: ReadBinError) -> Self
Source§impl From<SaveBinError> for ANNError
impl From<SaveBinError> for ANNError
Source§fn from(err: SaveBinError) -> Self
fn from(err: SaveBinError) -> Self
Source§impl<T> From<TryFromError<T>> for ANNErrorwhere
T: DenseData,
impl<T> From<TryFromError<T>> for ANNErrorwhere
T: DenseData,
Source§fn from(err: TryFromError<T>) -> Self
fn from(err: TryFromError<T>) -> Self
Source§impl From<TryFromErrorLight> for ANNError
impl From<TryFromErrorLight> for ANNError
Source§fn from(err: TryFromErrorLight) -> Self
fn from(err: TryFromErrorLight) -> Self
Source§impl From<TryFromIntError> for ANNError
impl From<TryFromIntError> for ANNError
Source§fn from(err: TryFromIntError) -> Self
fn from(err: TryFromIntError) -> Self
Source§impl From<TryFromSliceError> for ANNError
impl From<TryFromSliceError> for ANNError
Source§fn from(err: TryFromSliceError) -> Self
fn from(err: TryFromSliceError) -> Self
Source§impl ToRanked for ANNError
impl ToRanked for ANNError
type Transient = NeverTransient
type Error = ANNError
Source§fn to_ranked(self) -> RankedError<Self::Transient, Self::Error>
fn to_ranked(self) -> RankedError<Self::Transient, Self::Error>
self into a RankedError.Source§fn from_transient(_: NeverTransient) -> Self
fn from_transient(_: NeverTransient) -> Self
Self from its transient variant.Source§fn from_error(error: Self) -> Self
fn from_error(error: Self) -> Self
Self from its error variant.