Skip to content

Commit b292820

Browse files
author
skidy89
committed
ww
1 parent 5d08bcf commit b292820

1 file changed

Lines changed: 31 additions & 3 deletions

File tree

src/lib.rs

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@ pub struct LangError {
2727
pub message: String,
2828
}
2929

30+
#[napi(object)]
31+
pub struct JsLangError {
32+
pub code: String,
33+
pub severity: String,
34+
pub lang: String,
35+
pub engine: Option<String>,
36+
pub key: Option<String>,
37+
pub message: String,
38+
}
3039
use crate::{
3140
loader::{load_lang_dir, LangCache},
3241
parser::push_error,
@@ -59,7 +68,7 @@ pub fn get_languages<'a>(env: &'a Env) -> Result<Object<'a>> {
5968
}
6069

6170
#[napi]
62-
pub fn load_custom_language<'a>(dir: String, custom_dir: String) -> Result<bool> {
71+
pub fn load_custom_language<'a>(dir: String, custom_dir: String) -> Result<Vec<JsLangError>> {
6372
let base_langs = load_lang_dir(Path::new(&dir))?;
6473
let custom_langs = load_lang_dir(Path::new(&custom_dir))?;
6574

@@ -127,12 +136,31 @@ pub fn load_custom_language<'a>(dir: String, custom_dir: String) -> Result<bool>
127136
}
128137

129138
if errors.iter().any(|e| matches!(e.severity, Severity::Fatal)) {
130-
return Err(Error::from_reason("Fatal language errors detected"));
139+
return Err(Error::from_reason(
140+
"Fatal errors occurred while loading custom languages",
141+
));
131142
}
132143

133144
cache::clear();
134145
cache::set(merged);
135-
Ok(true)
146+
Ok(
147+
errors
148+
.into_iter()
149+
.map(|e| JsLangError {
150+
code: e.code,
151+
severity: match e.severity {
152+
Severity::Fatal => "Fatal".to_string(),
153+
Severity::Error => "Error".to_string(),
154+
Severity::Warning => "Warning".to_string(),
155+
Severity::Info => "Info".to_string(),
156+
},
157+
lang: e.lang,
158+
engine: e.engine,
159+
key: e.key,
160+
message: e.message,
161+
})
162+
.collect(),
163+
)
136164
}
137165

138166
fn to_js<'a>(env: &'a Env, langs: &LangCache) -> Result<Object<'a>> {

0 commit comments

Comments
 (0)