validation: rename error

This commit is contained in:
Quaternions 2025-04-03 15:25:02 -07:00
parent 1ff1cae709
commit 5ed15a6847
Signed by: Quaternions
GPG Key ID: D0DF5964F79AC131

@ -32,7 +32,7 @@ fn hash_source(source:&str)->String{
#[allow(dead_code)] #[allow(dead_code)]
#[derive(Debug)] #[derive(Debug)]
pub enum ValidateError{ pub enum Error{
ScriptFlaggedIllegalKeyword(String), ScriptFlaggedIllegalKeyword(String),
ScriptBlocked(Option<submissions_api::types::ScriptID>), ScriptBlocked(Option<submissions_api::types::ScriptID>),
ScriptNotYetReviewed(Option<submissions_api::types::ScriptID>), ScriptNotYetReviewed(Option<submissions_api::types::ScriptID>),
@ -51,12 +51,12 @@ pub enum ValidateError{
AssetUpload(rbx_asset::cookie::UploadError), AssetUpload(rbx_asset::cookie::UploadError),
AssetCreate(rbx_asset::cookie::CreateError), AssetCreate(rbx_asset::cookie::CreateError),
} }
impl std::fmt::Display for ValidateError{ impl std::fmt::Display for Error{
fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{ fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{
write!(f,"{self:?}") write!(f,"{self:?}")
} }
} }
impl std::error::Error for ValidateError{} impl std::error::Error for Error{}
#[allow(nonstandard_style)] #[allow(nonstandard_style)]
pub struct ValidateRequest{ pub struct ValidateRequest{
@ -88,15 +88,15 @@ impl From<crate::nats_types::ValidateSubmissionRequest> for ValidateRequest{
} }
impl crate::message_handler::MessageHandler{ impl crate::message_handler::MessageHandler{
pub async fn validate_inner(&self,validate_info:ValidateRequest)->Result<(),ValidateError>{ pub async fn validate_inner(&self,validate_info:ValidateRequest)->Result<(),Error>{
// download map // download map
let data=self.cookie_context.get_asset(rbx_asset::cookie::GetAssetRequest{ let data=self.cookie_context.get_asset(rbx_asset::cookie::GetAssetRequest{
asset_id:validate_info.ModelID, asset_id:validate_info.ModelID,
version:Some(validate_info.ModelVersion), version:Some(validate_info.ModelVersion),
}).await.map_err(ValidateError::ModelFileDownload)?; }).await.map_err(Error::ModelFileDownload)?;
// decode dom (slow!) // decode dom (slow!)
let mut dom=read_dom(&mut std::io::Cursor::new(data)).map_err(ValidateError::ModelFileDecode)?; let mut dom=read_dom(&mut std::io::Cursor::new(data)).map_err(Error::ModelFileDecode)?;
/* VALIDATE MAP */ /* VALIDATE MAP */
@ -111,7 +111,7 @@ impl crate::message_handler::MessageHandler{
// immediately abort // immediately abort
// grab path to offending script // grab path to offending script
let path=get_partial_path(&dom,script); let path=get_partial_path(&dom,script);
return Err(ValidateError::ScriptFlaggedIllegalKeyword(path)); return Err(Error::ScriptFlaggedIllegalKeyword(path));
} }
// associate a name and policy with the source code // associate a name and policy with the source code
// policy will be fetched from the database to replace the default policy // policy will be fetched from the database to replace the default policy
@ -132,7 +132,7 @@ impl crate::message_handler::MessageHandler{
// fetch the script policy // fetch the script policy
let script_policy=self.api.get_script_policy_from_hash(submissions_api::types::HashRequest{ let script_policy=self.api.get_script_policy_from_hash(submissions_api::types::HashRequest{
hash:hash.as_str(), hash:hash.as_str(),
}).await.map_err(ValidateError::ApiGetScriptPolicyFromHash)?; }).await.map_err(Error::ApiGetScriptPolicyFromHash)?;
// write the policy to the script_map, fetching the replacement code if necessary // write the policy to the script_map, fetching the replacement code if necessary
if let Some(script_policy)=script_policy{ if let Some(script_policy)=script_policy{
@ -144,7 +144,7 @@ impl crate::message_handler::MessageHandler{
submissions_api::types::Policy::Replace=>{ submissions_api::types::Policy::Replace=>{
let script=self.api.get_script(submissions_api::types::GetScriptRequest{ let script=self.api.get_script(submissions_api::types::GetScriptRequest{
ScriptID:script_policy.ToScriptID, ScriptID:script_policy.ToScriptID,
}).await.map_err(ValidateError::ApiGetScript)?; }).await.map_err(Error::ApiGetScript)?;
Policy::Replace(script.Source) Policy::Replace(script.Source)
}, },
}; };
@ -160,14 +160,14 @@ impl crate::message_handler::MessageHandler{
Source:source.as_str(), Source:source.as_str(),
ResourceType:resource_type, ResourceType:resource_type,
ResourceID:Some(resource_id), ResourceID:Some(resource_id),
}).await.map_err(ValidateError::ApiCreateScript)?; }).await.map_err(Error::ApiCreateScript)?;
// create a None policy (pending review by yours truly) // create a None policy (pending review by yours truly)
self.api.create_script_policy(submissions_api::types::CreateScriptPolicyRequest{ self.api.create_script_policy(submissions_api::types::CreateScriptPolicyRequest{
ToScriptID:script.ScriptID, ToScriptID:script.ScriptID,
FromScriptID:script.ScriptID, FromScriptID:script.ScriptID,
Policy:submissions_api::types::Policy::None, Policy:submissions_api::types::Policy::None,
}).await.map_err(ValidateError::ApiCreateScriptPolicy)?; }).await.map_err(Error::ApiCreateScriptPolicy)?;
} }
Ok(()) Ok(())
@ -184,8 +184,8 @@ impl crate::message_handler::MessageHandler{
let hash=hash_source(source.as_str()); let hash=hash_source(source.as_str());
let script=self.api.get_script_from_hash(submissions_api::types::HashRequest{ let script=self.api.get_script_from_hash(submissions_api::types::HashRequest{
hash:hash.as_str(), hash:hash.as_str(),
}).await.map_err(ValidateError::ApiGetScriptFromHash)?; }).await.map_err(Error::ApiGetScriptFromHash)?;
return Err(ValidateError::ScriptBlocked(script.map(|s|s.ID))); return Err(Error::ScriptBlocked(script.map(|s|s.ID)));
}, },
None None
|Some(Policy::None) |Some(Policy::None)
@ -193,8 +193,8 @@ impl crate::message_handler::MessageHandler{
let hash=hash_source(source.as_str()); let hash=hash_source(source.as_str());
let script=self.api.get_script_from_hash(submissions_api::types::HashRequest{ let script=self.api.get_script_from_hash(submissions_api::types::HashRequest{
hash:hash.as_str(), hash:hash.as_str(),
}).await.map_err(ValidateError::ApiGetScriptFromHash)?; }).await.map_err(Error::ApiGetScriptFromHash)?;
return Err(ValidateError::ScriptNotYetReviewed(script.map(|s|s.ID))); return Err(Error::ScriptNotYetReviewed(script.map(|s|s.ID)));
}, },
Some(Policy::Allowed)=>(), Some(Policy::Allowed)=>(),
Some(Policy::Delete)=>{ Some(Policy::Delete)=>{
@ -218,9 +218,9 @@ impl crate::message_handler::MessageHandler{
// serialize model (slow!) // serialize model (slow!)
let mut data=Vec::new(); let mut data=Vec::new();
let &[map_ref]=dom.root().children()else{ let &[map_ref]=dom.root().children()else{
return Err(ValidateError::ModelFileRootMustHaveOneChild); return Err(Error::ModelFileRootMustHaveOneChild);
}; };
rbx_binary::to_writer(&mut data,&dom,&[map_ref]).map_err(ValidateError::ModelFileEncode)?; rbx_binary::to_writer(&mut data,&dom,&[map_ref]).map_err(Error::ModelFileEncode)?;
// upload a model lol // upload a model lol
let model_id=if let Some(model_id)=validate_info.ValidatedModelID{ let model_id=if let Some(model_id)=validate_info.ValidatedModelID{
@ -232,13 +232,13 @@ impl crate::message_handler::MessageHandler{
ispublic:None, ispublic:None,
allowComments:None, allowComments:None,
groupId:None, groupId:None,
},data).await.map_err(ValidateError::AssetUpload)?; },data).await.map_err(Error::AssetUpload)?;
response.AssetId response.AssetId
}else{ }else{
// grab the map instance from the map re // grab the map instance from the map re
let Some(map_instance)=dom.get_by_ref(map_ref)else{ let Some(map_instance)=dom.get_by_ref(map_ref)else{
return Err(ValidateError::ModelFileChildRefIsNil); return Err(Error::ModelFileChildRefIsNil);
}; };
// create new model // create new model
let response=self.cookie_context.create(rbx_asset::cookie::CreateRequest{ let response=self.cookie_context.create(rbx_asset::cookie::CreateRequest{
@ -247,7 +247,7 @@ impl crate::message_handler::MessageHandler{
ispublic:true, ispublic:true,
allowComments:true, allowComments:true,
groupId:None, groupId:None,
},data).await.map_err(ValidateError::AssetCreate)?; },data).await.map_err(Error::AssetCreate)?;
response.AssetId response.AssetId
}; };
@ -259,7 +259,7 @@ impl crate::message_handler::MessageHandler{
MapfixID:mapfix_id, MapfixID:mapfix_id,
ModelID:model_id, ModelID:model_id,
ModelVersion:1, //TODO ModelVersion:1, //TODO
}).await.map_err(ValidateError::ApiUpdateMapfixModel)?; }).await.map_err(Error::ApiUpdateMapfixModel)?;
}, },
ResourceID::Submission(submission_id)=>{ ResourceID::Submission(submission_id)=>{
// update the submission to use the validated model // update the submission to use the validated model
@ -267,7 +267,7 @@ impl crate::message_handler::MessageHandler{
SubmissionID:submission_id, SubmissionID:submission_id,
ModelID:model_id, ModelID:model_id,
ModelVersion:1, //TODO ModelVersion:1, //TODO
}).await.map_err(ValidateError::ApiUpdateSubmissionModel)?; }).await.map_err(Error::ApiUpdateSubmissionModel)?;
}, },
} }
} }