explicit error path

This commit is contained in:
2025-08-25 18:59:01 -07:00
parent 71bbfa0128
commit 23d687e072

View File

@@ -1319,7 +1319,6 @@ async fn download_user_inventory_json(cookie:Cookie,user_id:u64,output_folder:Pa
Ok(())
}
/// Download all versions of all assets created by a group or user. The output is written to a folder structure in the output directory.
#[derive(Args)]
struct DownloadCreationsHistorySubcommand{
@@ -1366,14 +1365,6 @@ impl DownloadCreationsHistorySubcommand{
).await
}
}
#[derive(Debug)]
struct NoLocations;
impl std::fmt::Display for NoLocations{
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f,"{self:?}")
}
}
impl std::error::Error for NoLocations{}
async fn download_creations_history(cookie:Cookie,api_key:ApiKey,owner:rbx_asset::cookie::Owner,output_folder:PathBuf,r#continue:bool)->AResult<()>{
let cookie_context=CookieContext::new(cookie);
@@ -1395,6 +1386,15 @@ async fn download_creations_history(cookie:Cookie,api_key:ApiKey,owner:rbx_asset
.try_collect().await?
};
#[expect(dead_code)]
#[derive(Debug)]
enum Error<'a>{
NoLocations(Job<'a>),
GetVersionLocationError(rbx_asset::cloud::GetError),
GetError(rbx_asset::cloud::GetError),
Io(std::io::Error),
}
#[derive(Clone,Copy,Debug)]
struct Job<'a>{
path:&'a PathBuf,
asset_id:u64,
@@ -1435,18 +1435,22 @@ async fn download_creations_history(cookie:Cookie,api_key:ApiKey,owner:rbx_asset
let location=cloud_context.get_asset_version_location(rbx_asset::cloud::GetAssetVersionRequest{
asset_id:job.asset_id,
version:job.asset_version,
}).await?;
let location=location.location.ok_or(NoLocations)?;
let downloaded=cloud_context.get_asset(&location).await?;
Ok((job,downloaded))
})
.buffer_unordered(CONCURRENT_REQUESTS)
.try_for_each(async|(job,downloaded)|{
}).await.map_err(Error::GetVersionLocationError)?;
let location=location.location.ok_or(Error::NoLocations(job))?;
let downloaded=cloud_context.get_asset(&location).await.map_err(Error::GetError)?;
let mut dest=job.path.to_owned();
dest.push(format!("{}_v{}.rbxl",job.asset_id,job.asset_version));
tokio::fs::write(dest,downloaded.to_vec()?).await?;
Ok::<_,anyhow::Error>(())
}).await?;
tokio::fs::write(dest,downloaded.to_vec().map_err(Error::Io)?).await.map_err(Error::Io)?;
Ok::<_,Error>(())
})
.buffer_unordered(CONCURRENT_REQUESTS)
.for_each(async|result|{
match result{
Ok(())=>{},
Err(Error::NoLocations(job))=>println!("Job failed due to no locations: asset_id={} version={}",job.asset_id,job.asset_version),
Err(e)=>println!("Error: {e:?}"),
}
}).await;
println!("All jobs complete.");