This repository has been archived by the owner on May 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c507a5f
commit 15a8546
Showing
5 changed files
with
136 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
use serde::Serialize; | ||
use wasm_bindgen::JsValue; | ||
|
||
use crate::utils::IntoJsResult; | ||
|
||
// just a placeholder | ||
#[repr(i32)] | ||
pub enum CCode { | ||
/// A warning or uncritical error. | ||
Fault = -2, | ||
/// An irrecoverable error. | ||
Panic = -1, | ||
/// No error. | ||
Success = 0, | ||
/// A vocab null pointer error. | ||
VocabPointer = 1, | ||
/// A model null pointer error. | ||
ModelPointer = 2, | ||
/// A vocab or model file IO error. | ||
ReadFile = 3, | ||
/// A Xayn AI initialization error. | ||
InitAi = 4, | ||
/// A Xayn AI null pointer error. | ||
AiPointer = 5, | ||
/// A document histories null pointer error. | ||
HistoriesPointer = 6, | ||
/// A document history id null pointer error. | ||
HistoryIdPointer = 7, | ||
/// A documents null pointer error. | ||
DocumentsPointer = 8, | ||
/// A document id null pointer error. | ||
DocumentIdPointer = 9, | ||
/// A document snippet null pointer error. | ||
DocumentSnippetPointer = 10, | ||
/// Deserialization of reranker database error. | ||
RerankerDeserialization = 11, | ||
/// Serialization of reranker database error. | ||
RerankerSerialization = 12, | ||
/// Deserialization of history collection error. | ||
HistoriesDeserialization = 13, | ||
/// Deserialization of document collection error. | ||
DocumentsDeserialization = 14, | ||
} | ||
|
||
impl CCode { | ||
/// Provides context for the error code. | ||
pub fn with_context(self, message: impl Into<String>) -> ExternError { | ||
ExternError::new_error(self as i32, message) | ||
} | ||
} | ||
|
||
#[derive(Serialize)] | ||
pub struct ExternError { | ||
pub code: i32, | ||
pub message: String, | ||
} | ||
|
||
impl ExternError { | ||
fn new_error(code: i32, message: impl Into<String>) -> Self { | ||
Self { | ||
code, | ||
message: message.into(), | ||
} | ||
} | ||
} | ||
|
||
impl<T> IntoJsResult<T> for Result<T, ExternError> { | ||
fn into_js_result(self) -> Result<T, JsValue> { | ||
self.map_err(|e| JsValue::from_serde(&e).unwrap()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
pub mod ai; | ||
pub mod error; | ||
pub mod utils; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters