fallible functions cannot exist in the error suppressor

This commit is contained in:
Quaternions 2024-12-06 19:37:33 -08:00
parent 1a5e6e90c6
commit f99dbb1b9d

View File

@ -3,14 +3,12 @@ use crate::nats_types::ValidateRequest;
const SCRIPT_CONCURRENCY:usize=16; const SCRIPT_CONCURRENCY:usize=16;
struct ModelVersion{
model_id:u64,
model_version:u64,
}
enum Valid{ enum Valid{
Untouched, Untouched,
Modified(ModelVersion), Modified{
model_id:u64,
model_version:u64,
},
} }
enum Policy{ enum Policy{
@ -30,6 +28,7 @@ enum ValidateError{
ReadDom(ReadDomError), ReadDom(ReadDomError),
ApiGetScriptPolicy(api::Error), ApiGetScriptPolicy(api::Error),
ApiGetScript(api::Error), ApiGetScript(api::Error),
ApiUpdateSubmissionModel(api::Error),
WriteDom(rbx_binary::EncodeError), WriteDom(rbx_binary::EncodeError),
Upload(rbx_asset::cookie::UploadError), Upload(rbx_asset::cookie::UploadError),
Create(rbx_asset::cookie::CreateError), Create(rbx_asset::cookie::CreateError),
@ -66,16 +65,11 @@ impl Validator{
} }
async fn validate_supress_error(&self,message:async_nats::Message){ async fn validate_supress_error(&self,message:async_nats::Message){
match self.validate(message).await{ match self.validate(message).await{
Ok(valid)=>{ Ok(())=>println!("Validated, hooray!"),
unimplemented!(); Err(e)=>println!("There was an error, oopsie! {e}"),
// self.api.validate(validate_response).await.unwrap();
},
Err(e)=>{
println!("there was an error, oopsie! {e}");
}
} }
} }
async fn validate(&self,message:async_nats::Message)->Result<Valid,ValidateError>{ async fn validate(&self,message:async_nats::Message)->Result<(),ValidateError>{
println!("validate {:?}",message); println!("validate {:?}",message);
// decode json // decode json
let validate_info:ValidateRequest=serde_json::from_slice(&message.payload).map_err(ValidateError::Json)?; let validate_info:ValidateRequest=serde_json::from_slice(&message.payload).map_err(ValidateError::Json)?;
@ -102,7 +96,7 @@ impl Validator{
} }
} }
// send all scripts to REST endpoint and receive the replacements // send all script hashes to REST endpoint and retrieve the replacements
futures::stream::iter(script_map.iter_mut().map(Ok)) futures::stream::iter(script_map.iter_mut().map(Ok))
.try_for_each_concurrent(Some(SCRIPT_CONCURRENCY),|(source,replacement)|async{ .try_for_each_concurrent(Some(SCRIPT_CONCURRENCY),|(source,replacement)|async{
// get the hash // get the hash
@ -155,8 +149,8 @@ impl Validator{
} }
} }
// reply with validity // use a data structure to represent the validity
Ok(if modified{ let valid=if modified{
// serialize model (slow!) // serialize model (slow!)
let mut data=Vec::new(); let mut data=Vec::new();
rbx_binary::to_writer(&mut data,&dom,&[dom.root_ref()]).map_err(ValidateError::WriteDom)?; rbx_binary::to_writer(&mut data,&dom,&[dom.root_ref()]).map_err(ValidateError::WriteDom)?;
@ -192,13 +186,29 @@ impl Validator{
}; };
// tell the submission validate request to change the model // tell the submission validate request to change the model
Valid::Modified(ModelVersion{ Valid::Modified{
model_id, model_id,
model_version, model_version,
}) }
}else{ }else{
Valid::Untouched Valid::Untouched
}) };
// update the submission model if it was modified
match valid{
Valid::Untouched=>(),
Valid::Modified{model_id,model_version}=>{
// update the submission to use the validated model
self.api.update_submission_model(api::UpdateSubmissionModelRequest{
ID:validate_info.submission_id,
ModelID:model_id,
ModelVersion:model_version,
}).await.map_err(ValidateError::ApiUpdateSubmissionModel)?;
},
}
// update the submission model to display as validated
Ok(())
} }
} }