validator: move function call so get_model_info is infallible

This commit is contained in:
2025-04-11 21:46:44 -07:00
parent 57db5f738e
commit 668c5fef51

@ -127,10 +127,7 @@ pub struct ModelInfo<'a>{
counts:Counts, counts:Counts,
} }
pub fn get_model_info(dom:&rbx_dom_weak::WeakDom)->Result<ModelInfo,GetRootInstanceError>{ pub fn get_model_info<'a>(dom:&'a rbx_dom_weak::WeakDom,model_instance:&'a rbx_dom_weak::Instance)->ModelInfo<'a>{
// extract the root instance, otherwise immediately return
let model_instance=get_root_instance(&dom)?;
// extract model info // extract model info
let map_info=get_mapinfo(&dom,model_instance); let map_info=get_mapinfo(&dom,model_instance);
@ -161,12 +158,12 @@ pub fn get_model_info(dom:&rbx_dom_weak::WeakDom)->Result<ModelInfo,GetRootInsta
} }
} }
Ok(ModelInfo{ ModelInfo{
model_class:model_instance.class.as_str(), model_class:model_instance.class.as_str(),
model_name:model_instance.name.as_str(), model_name:model_instance.name.as_str(),
map_info, map_info,
counts, counts,
}) }
} }
// check if an observed string matches an expected string // check if an observed string matches an expected string
@ -515,8 +512,11 @@ impl crate::message_handler::MessageHandler{
// decode dom (slow!) // decode dom (slow!)
let dom=maybe_gzip.read_with(read_dom,read_dom).map_err(Error::ModelFileDecode)?; let dom=maybe_gzip.read_with(read_dom,read_dom).map_err(Error::ModelFileDecode)?;
// extract the root instance
let model_instance=get_root_instance(&dom).map_err(Error::GetRootInstance)?;
// extract information from the model // extract information from the model
let model_info=get_model_info(&dom).map_err(Error::GetRootInstance)?; let model_info=get_model_info(&dom,model_instance);
// convert the model information into a structured report // convert the model information into a structured report
let map_check=model_info.check(); let map_check=model_info.check();