refactor(core,shim): 统一基于 thiserror 的错误体系
- 移除 anyhow,使用 thiserror 定义强类型 Error 枚举 - 支持 #[from] 自动转换 mlua::Error,关键路径保留源码与上下文 - LuaRuntimeBuilder 采用惰性错误收集,简化链式初始化调用 - MirrorRegistry 实现规范化 FromLuaConversionError 错误转换
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
use mirror_core::error::validation_error;
|
||||
use anyhow::{Context, Result, anyhow};
|
||||
use mirror_core::validation_error;
|
||||
use mlua::{LuaString, Table, Value};
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::ffi::OsString;
|
||||
@@ -7,8 +7,8 @@ use std::fmt;
|
||||
use std::path::PathBuf;
|
||||
use std::str::FromStr;
|
||||
// use tinyjson::JsonValue;
|
||||
use tracing::debug;
|
||||
use crate::utils::{lua_string_2_os_string, parse_tokens};
|
||||
use tracing::debug;
|
||||
|
||||
/// Lua 值校验器:针对不同上下文定义校验规则
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
@@ -471,10 +471,10 @@ impl LuaValidator {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::Mirror;
|
||||
use crate::mirror::MirrorTarget;
|
||||
use mlua::{FromLua, Lua};
|
||||
|
||||
fn parse(src: &str) -> mlua::Result<Mirror> {
|
||||
fn parse(src: &str) -> mlua::Result<MirrorTarget> {
|
||||
let lua = Lua::new();
|
||||
// 模拟 runtime 注入的 get_env:返回按平台分隔符拆分的段数组(空变量返回空表)
|
||||
let get_env = lua
|
||||
@@ -493,7 +493,7 @@ mod tests {
|
||||
lua.globals().set("get_env", get_env).unwrap();
|
||||
|
||||
let value = lua.load(src).eval::<Value>()?;
|
||||
let t = Mirror::from_lua(value, &lua);
|
||||
let t = MirrorTarget::from_lua(value, &lua);
|
||||
println!("读取出的数据:{:?}", t.clone()?);
|
||||
t
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user