Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Use consumer-oriented Ensu errors

Manav Rathi65feb36250f6
diff --git a/rust/Cargo.lock b/rust/Cargo.lock
index f3221eacf8..862a0dc682 100644
--- a/rust/Cargo.lock
+++ b/rust/Cargo.lock
@@ -2549,6 +2549,7 @@ name = "ente-ensu-uniffi"
version = "0.0.0"
dependencies = [
"ente-assets",
+ "ente-core",
"ente-ensu",
"ente-uniffi-log",
"thiserror 2.0.18",
@@ -2560,9 +2561,11 @@ dependencies = [
name = "ente-ensu-wasm"
version = "0.0.0"
dependencies = [
+ "ente-core",
"ente-ensu-crypto",
"ente-wasm-log",
"js-sys",
+ "thiserror 2.0.18",
"wasm-bindgen",
]
diff --git a/rust/apps/ensu/src-tauri/src/commands/chat_db.rs b/rust/apps/ensu/src-tauri/src/commands/chat_db.rs
index 8cf483d8e8..230ec13a25 100644
--- a/rust/apps/ensu/src-tauri/src/commands/chat_db.rs
+++ b/rust/apps/ensu/src-tauri/src/commands/chat_db.rs
@@ -37,29 +37,7 @@ fn image_thread_error() -> ApiError {
impl From<db::Error> for ApiError {
fn from(error: db::Error) -> Self {
- use db::Error as E;
-
- let code = match &error {
- E::InvalidKeyLength { .. } => "db_invalid_key_length",
- E::InvalidBlobLength { .. } => "db_invalid_blob_length",
- E::InvalidEncryptedField => "db_invalid_encrypted_field",
- E::UnsupportedValueType(_) => "db_unsupported_value_type",
- E::Row(_) => "db_row",
- E::InvalidSender(_) => "db_invalid_sender",
- E::NotFound { .. } => "db_not_found",
- E::Crypto(_) => "db_crypto",
- E::Base64Decode(_) => "db_base64_decode",
- E::SerdeJson(_) => "db_serde_json",
- E::Uuid(_) => "db_uuid",
- E::Utf8(_) => "db_utf8",
- E::Io(_) => "db_io",
- E::ReadonlyDatabase => "db_readonly",
- E::Sqlite(_) => "db_sqlite",
- E::UnsupportedOperation(_) => "db_unsupported_operation",
- E::Migration(_) => "db_migration",
- };
-
- ApiError::new(code, error.to_string())
+ ApiError::other(ente_core::error::chain(&error))
}
}
@@ -549,7 +527,7 @@ fn finalize_assistant_text(
}
fn parse_uuid(value: &str) -> Result<Uuid, ApiError> {
- Uuid::parse_str(value).map_err(|error| ApiError::new("uuid", error.to_string()))
+ Ok(Uuid::parse_str(value).map_err(db::Error::from)?)
}
fn optional_uuid(value: &Option<String>) -> Result<Option<Uuid>, ApiError> {
diff --git a/rust/apps/ensu/src-tauri/src/commands/common.rs b/rust/apps/ensu/src-tauri/src/commands/common.rs
index db827b6009..8b9f49397a 100644
--- a/rust/apps/ensu/src-tauri/src/commands/common.rs
+++ b/rust/apps/ensu/src-tauri/src/commands/common.rs
@@ -7,14 +7,21 @@ use crate::logging;
#[derive(Debug, Serialize)]
pub struct ApiError {
- pub(crate) code: String,
+ pub(crate) name: Option<&'static str>,
pub(crate) message: String,
}
impl ApiError {
- pub(crate) fn new(code: &str, message: impl Into<String>) -> Self {
+ pub(crate) fn new(name: &'static str, message: impl Into<String>) -> Self {
Self {
- code: code.to_string(),
+ name: Some(name),
+ message: message.into(),
+ }
+ }
+
+ pub(crate) fn other(message: impl Into<String>) -> Self {
+ Self {
+ name: None,
message: message.into(),
}
}
diff --git a/rust/apps/ensu/src-tauri/src/commands/crypto.rs b/rust/apps/ensu/src-tauri/src/commands/crypto.rs
index 8dbb3f6c29..113e526ade 100644
--- a/rust/apps/ensu/src-tauri/src/commands/crypto.rs
+++ b/rust/apps/ensu/src-tauri/src/commands/crypto.rs
@@ -8,7 +8,7 @@ const SESSION_UUID_HEADER: &str = "session-uuid";
impl From<ente_ensu_crypto::Error> for ApiError {
fn from(error: ente_ensu_crypto::Error) -> Self {
- ApiError::new(error.code(), error.to_string())
+ ApiError::other(ente_core::error::chain(&error))
}
}
diff --git a/rust/bindings/uniffi/ensu/Cargo.toml b/rust/bindings/uniffi/ensu/Cargo.toml
index d4e718e951..a750c0c300 100644
--- a/rust/bindings/uniffi/ensu/Cargo.toml
+++ b/rust/bindings/uniffi/ensu/Cargo.toml
@@ -8,6 +8,7 @@ crate-type = ["staticlib", "cdylib"]
[dependencies]
ente-assets.workspace = true
+ente-core.workspace = true
ente-ensu = { workspace = true, features = ["transcription"] }
ente-uniffi-log.workspace = true
thiserror.workspace = true
diff --git a/rust/bindings/uniffi/ensu/src/db.rs b/rust/bindings/uniffi/ensu/src/db.rs
index 0e5d2eeef9..55b51746c1 100644
--- a/rust/bindings/uniffi/ensu/src/db.rs
+++ b/rust/bindings/uniffi/ensu/src/db.rs
@@ -4,92 +4,25 @@ use uuid::Uuid;
#[derive(Debug, Error, uniffi::Error)]
pub enum DbError {
- #[error("invalid encryption key length: expected {expected}, got {actual}")]
- InvalidKeyLength { expected: u64, actual: u64 },
- #[error("invalid blob length: expected at least {minimum} bytes, got {actual}")]
- InvalidBlobLength { minimum: u64, actual: u64 },
- #[error("invalid encrypted field format")]
- InvalidEncryptedField,
- #[error("unsupported value type: {detail}")]
- UnsupportedValueType { detail: String },
- #[error("row error: {detail}")]
- Row { detail: String },
- #[error("invalid sender: {detail}")]
- InvalidSender { detail: String },
- #[error("{entity} not found: {id}")]
- NotFound { entity: String, id: String },
- #[error("{detail}")]
- Crypto { detail: String },
- #[error("{detail}")]
- Json { detail: String },
- #[error("invalid UUID: {detail}")]
- InvalidUuid { detail: String },
- #[error("{detail}")]
- Utf8 { detail: String },
- #[error("{detail}")]
- Io { detail: String },
#[error("database is readonly")]
ReadonlyDatabase,
#[error("{detail}")]
- Sqlite { detail: String },
- #[error("unsupported operation: {detail}")]
- UnsupportedOperation { detail: String },
- #[error("migration error: {detail}")]
- Migration { detail: String },
+ Other { detail: String },
}
impl From<db::Error> for DbError {
- fn from(err: db::Error) -> Self {
- use db::Error as E;
- match err {
- E::InvalidKeyLength { expected, actual } => Self::InvalidKeyLength {
- expected: expected as u64,
- actual: actual as u64,
- },
- E::InvalidBlobLength { minimum, actual } => Self::InvalidBlobLength {
- minimum: minimum as u64,
- actual: actual as u64,
- },
- E::InvalidEncryptedField => Self::InvalidEncryptedField,
- E::UnsupportedValueType(detail) => Self::UnsupportedValueType { detail },
- E::Row(detail) => Self::Row { detail },
- E::InvalidSender(detail) => Self::InvalidSender { detail },
- E::NotFound { entity, id } => Self::NotFound {
- entity: format!("{entity:?}"),
- id: id.to_string(),
- },
- E::Crypto(err) => Self::Crypto {
- detail: err.to_string(),
+ fn from(error: db::Error) -> Self {
+ match error {
+ db::Error::ReadonlyDatabase => Self::ReadonlyDatabase,
+ error => Self::Other {
+ detail: ente_core::error::chain(&error),
},
- E::Base64Decode(err) => Self::Crypto {
- detail: err.to_string(),
- },
- E::SerdeJson(err) => Self::Json {
- detail: err.to_string(),
- },
- E::Uuid(err) => Self::InvalidUuid {
- detail: err.to_string(),
- },
- E::Utf8(err) => Self::Utf8 {
- detail: err.to_string(),
- },
- E::Io(err) => Self::Io {
- detail: err.to_string(),
- },
- E::ReadonlyDatabase => Self::ReadonlyDatabase,
- E::Sqlite(err) => Self::Sqlite {
- detail: err.to_string(),
- },
- E::UnsupportedOperation(detail) => Self::UnsupportedOperation { detail },
- E::Migration(detail) => Self::Migration { detail },
}
}
}
-fn invalid_uuid(err: uuid::Error) -> DbError {
- DbError::InvalidUuid {
- detail: err.to_string(),
- }
+fn parse_uuid(value: &str) -> db::Result<Uuid> {
+ Ok(Uuid::parse_str(value)?)
}
#[derive(Debug, Clone, uniffi::Record)]
@@ -231,17 +164,17 @@ impl EnsuDb {
}
pub fn get_session(&self, uuid: String) -> Result<Option<DbSession>, DbError> {
- let uuid = Uuid::parse_str(&uuid).map_err(invalid_uuid)?;
+ let uuid = parse_uuid(&uuid)?;
Ok(self.inner.get_session(uuid)?.map(to_session))
}
pub fn delete_session(&self, uuid: String) -> Result<Vec<String>, DbError> {
- let uuid = Uuid::parse_str(&uuid).map_err(invalid_uuid)?;
+ let uuid = parse_uuid(&uuid)?;
Ok(self.inner.delete_session(uuid)?)
}
pub fn update_session_title(&self, uuid: String, title: String) -> Result<(), DbError> {
- let uuid = Uuid::parse_str(&uuid).map_err(invalid_uuid)?;
+ let uuid = parse_uuid(&uuid)?;
Ok(self.inner.update_session_title(uuid, &title)?)
}
@@ -253,11 +186,8 @@ impl EnsuDb {
parent_message_uuid: Option<String>,
attachments: Vec<DbAttachmentMeta>,
) -> Result<DbMessage, DbError> {
- let session_uuid = Uuid::parse_str(&session_uuid).map_err(invalid_uuid)?;
- let parent = parent_message_uuid
- .map(|v| Uuid::parse_str(&v))
- .transpose()
- .map_err(invalid_uuid)?;
+ let session_uuid = parse_uuid(&session_uuid)?;
+ let parent = parent_message_uuid.as_deref().map(parse_uuid).transpose()?;
let message = self.inner.insert_message(
session_uuid,
@@ -270,7 +200,7 @@ impl EnsuDb {
}
pub fn get_messages(&self, session_uuid: String) -> Result<Vec<DbMessage>, DbError> {
- let session_uuid = Uuid::parse_str(&session_uuid).map_err(invalid_uuid)?;
+ let session_uuid = parse_uuid(&session_uuid)?;
Ok(self
.inner
.get_messages(session_uuid)?
@@ -280,7 +210,7 @@ impl EnsuDb {
}
pub fn update_message_text(&self, uuid: String, text: String) -> Result<(), DbError> {
- let uuid = Uuid::parse_str(&uuid).map_err(invalid_uuid)?;
+ let uuid = parse_uuid(&uuid)?;
Ok(self.inner.update_message_text(uuid, &text)?)
}
}
diff --git a/rust/bindings/wasm/ensu/Cargo.toml b/rust/bindings/wasm/ensu/Cargo.toml
index e8096ef359..d5fbbb14c7 100644
--- a/rust/bindings/wasm/ensu/Cargo.toml
+++ b/rust/bindings/wasm/ensu/Cargo.toml
@@ -6,7 +6,9 @@ edition = "2024"
crate-type = ["cdylib"]
[dependencies]
+ente-core.workspace = true
ente-ensu-crypto.workspace = true
ente-wasm-log.workspace = true
js-sys.workspace = true
+thiserror.workspace = true
wasm-bindgen.workspace = true
diff --git a/rust/bindings/wasm/ensu/src/lib.rs b/rust/bindings/wasm/ensu/src/lib.rs
index a4255b9260..3bace3d364 100644
--- a/rust/bindings/wasm/ensu/src/lib.rs
+++ b/rust/bindings/wasm/ensu/src/lib.rs
@@ -1,18 +1,28 @@
use ente_wasm_log as _;
use wasm_bindgen::prelude::*;
-pub struct WasmError(ente_ensu_crypto::Error);
+#[derive(Debug, thiserror::Error)]
+pub enum Error {
+ #[error(transparent)]
+ Crypto(#[from] ente_ensu_crypto::Error),
+}
+
+impl Error {
+ fn name(&self) -> Option<&'static str> {
+ None
+ }
-impl From<ente_ensu_crypto::Error> for WasmError {
- fn from(error: ente_ensu_crypto::Error) -> Self {
- Self(error)
+ fn message(&self) -> String {
+ ente_core::error::chain(self)
}
}
-impl From<WasmError> for JsValue {
- fn from(error: WasmError) -> Self {
- let js_error = js_sys::Error::new(&error.0.to_string());
- js_error.set_name(error.0.code());
+impl From<Error> for JsValue {
+ fn from(error: Error) -> Self {
+ let js_error = js_sys::Error::new(&error.message());
+ if let Some(name) = error.name() {
+ js_error.set_name(name);
+ }
js_error.into()
}
}
@@ -39,7 +49,7 @@ pub fn generate_chat_key() -> String {
}
#[wasm_bindgen(js_name = encryptChatPayload)]
-pub fn encrypt_chat_payload(value: &str, key_b64: &str) -> Result<EncryptedChatPayload, WasmError> {
+pub fn encrypt_chat_payload(value: &str, key_b64: &str) -> Result<EncryptedChatPayload, Error> {
ente_ensu_crypto::encrypt_payload(value, key_b64)
.map(EncryptedChatPayload)
.map_err(Into::into)
@@ -50,17 +60,17 @@ pub fn decrypt_chat_payload(
encrypted_data_b64: &str,
header_b64: &str,
key_b64: &str,
-) -> Result<String, WasmError> {
+) -> Result<String, Error> {
ente_ensu_crypto::decrypt_payload(encrypted_data_b64, header_b64, key_b64).map_err(Into::into)
}
#[wasm_bindgen(js_name = encryptChatField)]
-pub fn encrypt_chat_field(value: &str, key_b64: &str) -> Result<String, WasmError> {
+pub fn encrypt_chat_field(value: &str, key_b64: &str) -> Result<String, Error> {
ente_ensu_crypto::encrypt_field_b64(value, key_b64).map_err(Into::into)
}
#[wasm_bindgen(js_name = decryptChatField)]
-pub fn decrypt_chat_field(value: &str, key_b64: &str) -> Result<String, WasmError> {
+pub fn decrypt_chat_field(value: &str, key_b64: &str) -> Result<String, Error> {
ente_ensu_crypto::decrypt_field_b64(value, key_b64).map_err(Into::into)
}
@@ -69,7 +79,7 @@ pub fn encrypt_chat_attachment(
data: &[u8],
key_b64: &str,
session_uuid: &str,
-) -> Result<Vec<u8>, WasmError> {
+) -> Result<Vec<u8>, Error> {
ente_ensu_crypto::encrypt_attachment(data, key_b64, session_uuid).map_err(Into::into)
}
@@ -78,6 +88,6 @@ pub fn decrypt_chat_attachment(
data: &[u8],
key_b64: &str,
session_uuid: &str,
-) -> Result<Vec<u8>, WasmError> {
+) -> Result<Vec<u8>, Error> {
ente_ensu_crypto::decrypt_attachment(data, key_b64, session_uuid).map_err(Into::into)
}
diff --git a/rust/crates/core/src/crypto/error.rs b/rust/crates/core/src/crypto/error.rs
index c6c2d15174..7d8539e7f4 100644
--- a/rust/crates/core/src/crypto/error.rs
+++ b/rust/crates/core/src/crypto/error.rs
@@ -66,35 +66,6 @@ pub enum Error {
Io(#[from] std::io::Error),
}
-impl Error {
- // Bindings expose these strings to non-Rust callers.
- pub fn code(&self) -> &'static str {
- match self {
- Error::InvalidKeyLength { .. } => "invalid_key_length",
- Error::InvalidNonceLength { .. } => "invalid_nonce_length",
- Error::InvalidSaltLength { .. } => "invalid_salt_length",
- Error::InvalidHeaderLength { .. } => "invalid_header_length",
- Error::CiphertextTooShort { .. } => "ciphertext_too_short",
- Error::InvalidKeyDerivationParams(_) => "invalid_kdf_params",
- Error::KeyDerivationFailed => "key_derivation_failed",
- Error::EncryptionFailed => "encryption_failed",
- Error::DecryptionFailed => "decryption_failed",
- Error::StreamInitFailed => "stream_init_failed",
- Error::StreamPushFailed => "stream_push_failed",
- Error::StreamPullFailed => "stream_pull_failed",
- Error::StreamTruncated => "stream_truncated",
- Error::StreamTrailingData => "stream_trailing_data",
- Error::SealedBoxOpenFailed => "sealed_box_open_failed",
- Error::InvalidPublicKey => "invalid_public_key",
- Error::Json(_) => "json",
- Error::Argon2(_) => "argon2",
- Error::Aead => "aead",
- Error::ArrayConversion => "array_conversion",
- Error::Io(_) => "io",
- }
- }
-}
-
pub type Result<T> = std::result::Result<T, Error>;
impl From<std::array::TryFromSliceError> for Error {
diff --git a/rust/crates/ensu-crypto/src/lib.rs b/rust/crates/ensu-crypto/src/lib.rs
index c8244531f1..3d2f6b3662 100644
--- a/rust/crates/ensu-crypto/src/lib.rs
+++ b/rust/crates/ensu-crypto/src/lib.rs
@@ -28,18 +28,6 @@ pub enum Error {
Utf8(#[from] std::string::FromUtf8Error),
}
-impl Error {
- pub fn code(&self) -> &'static str {
- match self {
- Self::InvalidBlobLength { .. } => "invalid_blob_length",
- Self::InvalidEncryptedField => "invalid_encrypted_field",
- Self::Crypto(error) => error.code(),
- Self::Base64Decode(_) => "base64_decode",
- Self::Utf8(_) => "invalid_utf8",
- }
- }
-}
-
pub struct EncryptedChatPayload {
pub encrypted_data: String,
pub header: String,
diff --git a/web/apps/ensu/src/pages/chat.tsx b/web/apps/ensu/src/pages/chat.tsx
index de3f6aca61..3f4bfcc5e2 100644
--- a/web/apps/ensu/src/pages/chat.tsx
+++ b/web/apps/ensu/src/pages/chat.tsx
@@ -104,7 +104,7 @@ const MODEL_SETTINGS_STORAGE_KEY = "ensu.modelSettings";
const SYSTEM_PROMPT_STORAGE_KEY = "ensu.systemPrompt";
interface TauriCommandError {
- code?: string;
+ name?: string;
message?: string;
}
@@ -112,15 +112,15 @@ const tauriCommandError = (error: unknown): TauriCommandError => {
if (!error || typeof error != "object") return {};
const record = error as Record<string, unknown>;
return {
- code: typeof record.code == "string" ? record.code : undefined,
+ name: typeof record.name == "string" ? record.name : undefined,
message: typeof record.message == "string" ? record.message : undefined,
};
};
const formatImageProcessingErrorForLog = (error: unknown) => {
- const { code, message } = tauriCommandError(error);
- if (code == "io") return "io: selected image file could not be read";
- if (code && message) return `${code}: ${message}`;
+ const { name, message } = tauriCommandError(error);
+ if (name == "io") return "io: selected image file could not be read";
+ if (name && message) return `${name}: ${message}`;
if (message) return message;
if (error instanceof Error) return error.message;
if (typeof error == "string") return error;
@@ -131,28 +131,28 @@ const imageProcessingFailureDialog = (
error: unknown,
selectedImageCount: number,
) => {
- const { code, message } = tauriCommandError(error);
+ const { name, message } = tauriCommandError(error);
const lowerMessage = message?.toLowerCase() ?? "";
const subject =
selectedImageCount == 1
? "The selected image"
: "One of the selected images";
- if (code == "image" && lowerMessage.includes("memory limit")) {
+ if (name == "image" && lowerMessage.includes("memory limit")) {
return {
title: "Image too large",
message: `${subject} is too large for Ensu to process. Try resizing it or exporting a smaller copy, then attach it again.`,
};
}
- if (code == "image") {
+ if (name == "image") {
return {
title: "Image could not be attached",
message: `${subject} could not be decoded. Try converting it to a different image format, then attach it again.`,
};
}
- if (code == "io") {
+ if (name == "io") {
return {
title: "Image file could not be read",
message: `${subject} could not be read. Check that the file still exists and try again.`,
@@ -2200,8 +2200,8 @@ const Page: React.FC = () => {
setModelGateStatus("ready");
} catch (error) {
if (!isCurrentRequest()) return;
- const { code } = tauriCommandError(error);
- if (code === "model_missing" || code === "not_found") {
+ const { name } = tauriCommandError(error);
+ if (name === "model_missing" || name === "not_found") {
setModelGateError(null);
setIsDownloading(false);
setDownloadStatus(null);
@@ -3124,11 +3124,11 @@ const Page: React.FC = () => {
);
if (!isActiveGeneration()) return;
} catch (error) {
- const { code } = tauriCommandError(error);
- if (!isActiveGeneration() || code === "cancelled") {
+ const { name } = tauriCommandError(error);
+ if (!isActiveGeneration() || name === "cancelled") {
return;
}
- if (code === "embedding_missing") {
+ if (name === "embedding_missing") {
throw error;
}
log.warn(
@@ -3224,9 +3224,9 @@ const Page: React.FC = () => {
try {
await generate();
} catch (error) {
- const { code } = tauriCommandError(error);
+ const { name } = tauriCommandError(error);
if (
- code === "prompt_too_long" &&
+ name === "prompt_too_long" &&
!streamingBufferRef.current &&
streamingChunksRef.current.length === 0 &&
activeCitations.length > 0
@@ -3312,11 +3312,11 @@ const Page: React.FC = () => {
if (!isActiveGeneration()) {
return;
}
- const { code } = tauriCommandError(error);
+ const { name } = tauriCommandError(error);
if (
- code === "model_missing" ||
- code === "not_found" ||
- code === "embedding_missing"
+ name === "model_missing" ||
+ name === "not_found" ||
+ name === "embedding_missing"
) {
setModelGateError(null);
setDownloadStatus(null);
@@ -3646,8 +3646,8 @@ const Page: React.FC = () => {
}
})
.catch((error: unknown) => {
- const { code } = tauriCommandError(error);
- if (code !== "cancelled") {
+ const { name } = tauriCommandError(error);
+ if (name !== "cancelled") {
setKnowledgeErrors((current) => ({
...current,
[stableId]: knowledgeErrorMessage(error),
diff --git a/web/apps/ensu/src/services/knowledge.ts b/web/apps/ensu/src/services/knowledge.ts
index 891c678785..d76e22fe66 100644
--- a/web/apps/ensu/src/services/knowledge.ts
+++ b/web/apps/ensu/src/services/knowledge.ts
@@ -130,10 +130,10 @@ export const saveEnabledKnowledgePacks = (stableIds: Set<string>) => {
export const knowledgeErrorMessage = (error: unknown) => {
const record =
error && typeof error === "object"
- ? (error as { code?: unknown; message?: unknown })
+ ? (error as { name?: unknown })
: undefined;
- const code = typeof record?.code === "string" ? record.code : undefined;
- switch (code) {
+ const name = typeof record?.name === "string" ? record.name : undefined;
+ switch (name) {
case "storage_full":
return "Not enough storage space to download this knowledge pack.";
case "network":
diff --git a/web/apps/ensu/src/services/llm/inference.ts b/web/apps/ensu/src/services/llm/inference.ts
index 773110472c..43771c1218 100644
--- a/web/apps/ensu/src/services/llm/inference.ts
+++ b/web/apps/ensu/src/services/llm/inference.ts
@@ -689,24 +689,13 @@ const normalizeInvokeError = (error: unknown, fallback: string) => {
if (error instanceof Error) return error;
if (typeof error === "string") return new Error(error);
if (error && typeof error === "object") {
- const code =
- "code" in error
- ? String((error as { code?: unknown }).code)
- : undefined;
- const message =
- "message" in error
- ? String((error as { message?: unknown }).message)
- : "";
+ const value = error as { name?: unknown; message?: unknown };
+ const name = typeof value.name === "string" ? value.name : undefined;
+ const message = typeof value.message === "string" ? value.message : "";
const payload = message || safeJson(error);
- const text = payload
- ? code
- ? `${payload} (${code})`
- : payload
- : fallback;
+ const text = payload || fallback;
const err = new Error(text);
- if (code) {
- (err as Error & { code?: string }).code = code;
- }
+ if (name) err.name = name;
return err;
}
return new Error(fallback);
diff --git a/web/apps/ensu/src/services/llm/provider.ts b/web/apps/ensu/src/services/llm/provider.ts
index 9573356838..adbd057e9a 100644
--- a/web/apps/ensu/src/services/llm/provider.ts
+++ b/web/apps/ensu/src/services/llm/provider.ts
@@ -135,7 +135,7 @@ const MODEL_INFO_FALLBACKS = [
const modelMissingError = () =>
Object.assign(new Error("Required model assets are not downloaded"), {
- code: "model_missing",
+ name: "model_missing",
});
export class LlmProvider {
@@ -466,7 +466,7 @@ export class LlmProvider {
await this.ensureInFlight?.promise.catch(() => undefined);
if (!shouldContinue()) {
throw Object.assign(new Error("Knowledge retrieval cancelled"), {
- code: "cancelled",
+ name: "cancelled",
});
}
this.invalidateModelState();