mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-06 20:58:28 +00:00
Added I/O errors to de/serializing
This commit is contained in:
40
lib/cache/src/filesystem.rs
vendored
40
lib/cache/src/filesystem.rs
vendored
@@ -6,28 +6,6 @@ use std::path::PathBuf;
|
||||
use thiserror::Error;
|
||||
use wasmer::{DeserializeError, Module, SerializeError, Store};
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
/// The Io Serialization error
|
||||
pub enum IoSerializeError {
|
||||
/// An IO error
|
||||
#[error(transparent)]
|
||||
Io(#[from] io::Error),
|
||||
/// A serialization error
|
||||
#[error(transparent)]
|
||||
Serialize(#[from] SerializeError),
|
||||
}
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
/// The Io Deserialization error
|
||||
pub enum IoDeserializeError {
|
||||
/// An IO error
|
||||
#[error(transparent)]
|
||||
Io(#[from] io::Error),
|
||||
/// A serialization error
|
||||
#[error(transparent)]
|
||||
Deserialize(#[from] DeserializeError),
|
||||
}
|
||||
|
||||
/// Representation of a directory that contains compiled wasm artifacts.
|
||||
///
|
||||
/// The `FileSystemCache` type implements the [`Cache`] trait, which allows it to be used
|
||||
@@ -38,10 +16,11 @@ pub enum IoDeserializeError {
|
||||
///
|
||||
/// ## Store
|
||||
/// ```
|
||||
/// use wasmer_cache::{Cache, IoSerializeError, FileSystemCache, WasmHash};
|
||||
/// use wasmer::{DeserializeError, SerializeError};
|
||||
/// use wasmer_cache::{Cache, FileSystemCache, WasmHash};
|
||||
///
|
||||
/// # use wasmer::{Module};
|
||||
/// fn store_module(module: Module) -> Result<Module, IoSerializeError> {
|
||||
/// fn store_module(module: Module) -> Result<Module, SerializeError> {
|
||||
/// // Create a new file system cache.
|
||||
/// let mut fs_cache = FileSystemCache::new("some/directory/goes/here")?;
|
||||
/// // Compute a key for a given WebAssembly binary
|
||||
@@ -90,21 +69,14 @@ impl FileSystemCache {
|
||||
}
|
||||
|
||||
impl Cache for FileSystemCache {
|
||||
type DeserializeError = IoDeserializeError;
|
||||
type SerializeError = IoSerializeError;
|
||||
type DeserializeError = DeserializeError;
|
||||
type SerializeError = SerializeError;
|
||||
|
||||
unsafe fn load(&self, store: &Store, key: WasmHash) -> Result<Module, Self::DeserializeError> {
|
||||
let filename = key.to_string();
|
||||
let mut new_path_buf = self.path.clone();
|
||||
new_path_buf.push(filename);
|
||||
if new_path_buf.exists() {
|
||||
Ok(Module::deserialize_from_file(&store, new_path_buf)?)
|
||||
} else {
|
||||
Err(IoDeserializeError::Io(io::Error::new(
|
||||
io::ErrorKind::NotFound,
|
||||
format!("The path `{}` doesn't exist", new_path_buf.display()),
|
||||
)))
|
||||
}
|
||||
Module::deserialize_from_file(&store, new_path_buf)
|
||||
}
|
||||
|
||||
fn store(&mut self, key: WasmHash, module: Module) -> Result<(), Self::SerializeError> {
|
||||
|
||||
Reference in New Issue
Block a user