mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-04-25 15:16:07 +00:00
Improve SnapshotError in preparation for moving middleware to it
This commit is contained in:
@@ -39,6 +39,10 @@ impl FsError {
|
|||||||
pub fn kind(&self) -> FsErrorKind {
|
pub fn kind(&self) -> FsErrorKind {
|
||||||
self.inner.kind()
|
self.inner.kind()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn into_raw(self) -> (io::Error, PathBuf) {
|
||||||
|
(self.inner, self.path)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for FsError {
|
impl fmt::Display for FsError {
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
use std::{error::Error, fmt, path::PathBuf};
|
use std::{error::Error, fmt, io, path::PathBuf};
|
||||||
|
|
||||||
use crate::snapshot::InstanceSnapshot;
|
use crate::{imfs::FsError, snapshot::InstanceSnapshot};
|
||||||
|
|
||||||
pub type SnapshotResult<'a> = Result<Option<InstanceSnapshot<'a>>, SnapshotError>;
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct SnapshotError {
|
pub struct SnapshotError {
|
||||||
@@ -58,8 +56,19 @@ impl fmt::Display for SnapshotError {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<FsError> for SnapshotError {
|
||||||
|
fn from(error: FsError) -> Self {
|
||||||
|
let (inner, path) = error.into_raw();
|
||||||
|
|
||||||
|
let detail = SnapshotErrorDetail::IoError { inner };
|
||||||
|
|
||||||
|
Self::new(detail, Some(path))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum SnapshotErrorDetail {
|
pub enum SnapshotErrorDetail {
|
||||||
|
IoError { inner: io::Error },
|
||||||
FileDidNotExist,
|
FileDidNotExist,
|
||||||
FileNameBadUnicode,
|
FileNameBadUnicode,
|
||||||
FileContentsBadUnicode { inner: std::str::Utf8Error },
|
FileContentsBadUnicode { inner: std::str::Utf8Error },
|
||||||
@@ -70,6 +79,7 @@ impl SnapshotErrorDetail {
|
|||||||
use self::SnapshotErrorDetail::*;
|
use self::SnapshotErrorDetail::*;
|
||||||
|
|
||||||
match self {
|
match self {
|
||||||
|
IoError { inner } => Some(inner),
|
||||||
FileContentsBadUnicode { inner } => Some(inner),
|
FileContentsBadUnicode { inner } => Some(inner),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
@@ -81,6 +91,7 @@ impl fmt::Display for SnapshotErrorDetail {
|
|||||||
use self::SnapshotErrorDetail::*;
|
use self::SnapshotErrorDetail::*;
|
||||||
|
|
||||||
match self {
|
match self {
|
||||||
|
IoError { inner } => write!(formatter, "I/O error: {}", inner),
|
||||||
FileDidNotExist => write!(formatter, "file did not exist"),
|
FileDidNotExist => write!(formatter, "file did not exist"),
|
||||||
FileNameBadUnicode => write!(formatter, "file name had malformed Unicode"),
|
FileNameBadUnicode => write!(formatter, "file name had malformed Unicode"),
|
||||||
FileContentsBadUnicode { inner } => {
|
FileContentsBadUnicode { inner } => {
|
||||||
|
|||||||
Reference in New Issue
Block a user