Error types

This commit is contained in:
Louis Dureuil 2025-02-24 13:55:40 +01:00
parent 3cdcc54a9e
commit b85180fedb
No known key found for this signature in database
2 changed files with 53 additions and 18 deletions

View File

@ -428,9 +428,10 @@ impl ErrorCode for milli::Error {
| UserError::InvalidUrl { .. } | UserError::InvalidUrl { .. }
| UserError::InvalidSettingsDocumentTemplateMaxBytes { .. } | UserError::InvalidSettingsDocumentTemplateMaxBytes { .. }
| UserError::InvalidPrompt(_) | UserError::InvalidPrompt(_)
| UserError::InvalidDisableBinaryQuantization { .. } => { | UserError::InvalidDisableBinaryQuantization { .. }
Code::InvalidSettingsEmbedders | UserError::InvalidSourceForNested { .. }
} | UserError::MissingSourceForNested { .. }
| UserError::InvalidSettingsEmbedder { .. } => Code::InvalidSettingsEmbedders,
UserError::TooManyEmbedders(_) => Code::InvalidSettingsEmbedders, UserError::TooManyEmbedders(_) => Code::InvalidSettingsEmbedders,
UserError::InvalidPromptForEmbeddings(..) => Code::InvalidSettingsEmbedders, UserError::InvalidPromptForEmbeddings(..) => Code::InvalidSettingsEmbedders,
UserError::NoPrimaryKeyCandidateFound => Code::IndexPrimaryKeyNoCandidateFound, UserError::NoPrimaryKeyCandidateFound => Code::IndexPrimaryKeyNoCandidateFound,

View File

@ -13,6 +13,7 @@ use thiserror::Error;
use crate::constants::RESERVED_GEO_FIELD_NAME; use crate::constants::RESERVED_GEO_FIELD_NAME;
use crate::documents::{self, DocumentsBatchCursorError}; use crate::documents::{self, DocumentsBatchCursorError};
use crate::thread_pool_no_abort::PanicCatched; use crate::thread_pool_no_abort::PanicCatched;
use crate::vector::settings::EmbeddingSettings;
use crate::{CriterionError, DocumentId, FieldId, Object, SortError}; use crate::{CriterionError, DocumentId, FieldId, Object, SortError};
pub fn is_reserved_keyword(keyword: &str) -> bool { pub fn is_reserved_keyword(keyword: &str) -> bool {
@ -229,28 +230,52 @@ and can not be more than 511 bytes.", .document_id.to_string()
InvalidSimilarEmbedder(String), InvalidSimilarEmbedder(String),
#[error("Too many vectors for document with id {0}: found {1}, but limited to 256.")] #[error("Too many vectors for document with id {0}: found {1}, but limited to 256.")]
TooManyVectors(String, usize), TooManyVectors(String, usize),
#[error("`.embedders.{embedder_name}`: Field `{field}` unavailable for source `{source_}` (only available for sources: {}). Available fields: {}", #[error("`.embedders.{embedder_name}`: Field `{field}` unavailable for source `{source_}`{for_context}.{available_sources}{available_fields}{available_contexts}",
allowed_sources_for_field field=field.name(),
.iter() for_context={
.map(|accepted| format!("`{}`", accepted)) context.in_context()
.collect::<Vec<String>>() },
.join(", "), available_sources={
allowed_fields_for_source let allowed_sources_for_field = EmbeddingSettings::allowed_sources_for_field(*field, *context);
.iter() if allowed_sources_for_field.is_empty() {
.map(|accepted| format!("`{}`", accepted)) String::new()
.collect::<Vec<String>>() } else {
.join(", ") format!("\n - note: `{}` is available for sources: {}",
field.name(),
allowed_sources_for_field
.iter()
.map(|accepted| format!("`{}`", accepted))
.collect::<Vec<String>>()
.join(", "),
)
}
},
available_fields={
let allowed_fields_for_source = EmbeddingSettings::allowed_fields_for_source(*source_, *context);
format!("\n - note: available fields for source `{source_}`{}: {}",context.in_context(), allowed_fields_for_source
.iter()
.map(|accepted| format!("`{}`", accepted))
.collect::<Vec<String>>()
.join(", "),)
},
available_contexts={
let available_not_nested = !matches!(EmbeddingSettings::field_status(*source_, *field, crate::vector::settings::NestingContext::NotNested), crate::vector::settings::FieldStatus::Disallowed);
if available_not_nested {
format!("\n - note: `{}` is available when source `{source_}` is not{}", field.name(), context.in_context())
} else {
String::new()
}
}
)] )]
InvalidFieldForSource { InvalidFieldForSource {
embedder_name: String, embedder_name: String,
source_: crate::vector::settings::EmbedderSource, source_: crate::vector::settings::EmbedderSource,
field: &'static str, context: crate::vector::settings::NestingContext,
allowed_fields_for_source: &'static [&'static str], field: crate::vector::settings::MetaEmbeddingSetting,
allowed_sources_for_field: &'static [crate::vector::settings::EmbedderSource],
}, },
#[error("`.embedders.{embedder_name}.model`: Invalid model `{model}` for OpenAI. Supported models: {:?}", crate::vector::openai::EmbeddingModel::supported_models())] #[error("`.embedders.{embedder_name}.model`: Invalid model `{model}` for OpenAI. Supported models: {:?}", crate::vector::openai::EmbeddingModel::supported_models())]
InvalidOpenAiModel { embedder_name: String, model: String }, InvalidOpenAiModel { embedder_name: String, model: String },
#[error("`.embedders.{embedder_name}`: Missing field `{field}` (note: this field is mandatory for source {source_})")] #[error("`.embedders.{embedder_name}`: Missing field `{field}` (note: this field is mandatory for source `{source_}`)")]
MissingFieldForSource { MissingFieldForSource {
field: &'static str, field: &'static str,
source_: crate::vector::settings::EmbedderSource, source_: crate::vector::settings::EmbedderSource,
@ -270,6 +295,15 @@ and can not be more than 511 bytes.", .document_id.to_string()
dimensions: usize, dimensions: usize,
max_dimensions: usize, max_dimensions: usize,
}, },
#[error("`.embedders.{embedder_name}.source`: Source `{source_}` is not available in a nested embedder")]
InvalidSourceForNested {
embedder_name: String,
source_: crate::vector::settings::EmbedderSource,
},
#[error("`.embedders.{embedder_name}`: Missing field `source`.\n - note: this field is mandatory for nested embedders")]
MissingSourceForNested { embedder_name: String },
#[error("`.embedders.{embedder_name}`: {message}")]
InvalidSettingsEmbedder { embedder_name: String, message: String },
#[error("`.embedders.{embedder_name}.dimensions`: `dimensions` cannot be zero")] #[error("`.embedders.{embedder_name}.dimensions`: `dimensions` cannot be zero")]
InvalidSettingsDimensions { embedder_name: String }, InvalidSettingsDimensions { embedder_name: String },
#[error( #[error(