forked from rojo-rbx/rojo
User plugin foundations for 0.6.0 (#257)
Starts work on #55. This is similar to the previous work in #125. It's gated behind a new Cargo feature, `user-plugins`. This time, the config gate is much smaller. The `plugins` member of projects is still accessible when plugins aren't enabled, but is always empty. Additionally, user plugins are only enabled if there's a Lua state present in the snapshot context when the `SnapshotUserPlugins` snapshot middleware runs. This not ever the case currently. This code has very little possibility of rotting while we focus on other work, since it'll be guaranteed to still compile and can be tested in isolation without the feature being turned on.
This commit is contained in:
committed by
GitHub
parent
f3dc78b7cd
commit
b093626a21
@@ -16,6 +16,13 @@ impl SnapshotError {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn wrap(inner: impl Into<SnapshotErrorDetail>, path: impl Into<PathBuf>) -> Self {
|
||||
SnapshotError {
|
||||
detail: inner.into(),
|
||||
path: Some(path.into()),
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn file_did_not_exist(path: impl Into<PathBuf>) -> SnapshotError {
|
||||
SnapshotError {
|
||||
detail: SnapshotErrorDetail::FileDidNotExist,
|
||||
@@ -70,27 +77,45 @@ impl From<FsError> for SnapshotError {
|
||||
fn from(error: FsError) -> Self {
|
||||
let (inner, path) = error.into_raw();
|
||||
|
||||
let detail = SnapshotErrorDetail::IoError { inner };
|
||||
Self::new(inner.into(), Some(path))
|
||||
}
|
||||
}
|
||||
|
||||
Self::new(detail, Some(path))
|
||||
impl From<rlua::Error> for SnapshotError {
|
||||
fn from(error: rlua::Error) -> Self {
|
||||
Self::new(error.into(), Option::<PathBuf>::None)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum SnapshotErrorDetail {
|
||||
IoError { inner: io::Error },
|
||||
Lua { inner: rlua::Error },
|
||||
FileDidNotExist,
|
||||
FileNameBadUnicode,
|
||||
FileContentsBadUnicode { inner: std::str::Utf8Error },
|
||||
MalformedProject { inner: serde_json::Error },
|
||||
}
|
||||
|
||||
impl From<io::Error> for SnapshotErrorDetail {
|
||||
fn from(inner: io::Error) -> Self {
|
||||
SnapshotErrorDetail::IoError { inner }
|
||||
}
|
||||
}
|
||||
|
||||
impl From<rlua::Error> for SnapshotErrorDetail {
|
||||
fn from(inner: rlua::Error) -> Self {
|
||||
SnapshotErrorDetail::Lua { inner }
|
||||
}
|
||||
}
|
||||
|
||||
impl SnapshotErrorDetail {
|
||||
fn source(&self) -> Option<&(dyn Error + 'static)> {
|
||||
use self::SnapshotErrorDetail::*;
|
||||
|
||||
match self {
|
||||
IoError { inner } => Some(inner),
|
||||
Lua { inner } => Some(inner),
|
||||
FileContentsBadUnicode { inner } => Some(inner),
|
||||
MalformedProject { inner } => Some(inner),
|
||||
_ => None,
|
||||
@@ -104,6 +129,7 @@ impl fmt::Display for SnapshotErrorDetail {
|
||||
|
||||
match self {
|
||||
IoError { inner } => write!(formatter, "I/O error: {}", inner),
|
||||
Lua { inner } => write!(formatter, "{}", inner),
|
||||
FileDidNotExist => write!(formatter, "file did not exist"),
|
||||
FileNameBadUnicode => write!(formatter, "file name had malformed Unicode"),
|
||||
FileContentsBadUnicode { inner } => {
|
||||
|
||||
Reference in New Issue
Block a user