mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-04-25 15:16:07 +00:00
Fix returning NoProjectFound for any project load error (#985)
In #917, we accidentally changed ServeSession::new's project loading logic so that it always returns `ServeSession::ProjectNotFound` if the load fails for any reason. This PR fixes this so that it returns the right error when there is an error loading the project, and moves the `NoProjectFound` error to `project::Error`, since I think it makes more sense there.
This commit is contained in:
@@ -10,10 +10,7 @@ use memofs::Vfs;
|
|||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
use crate::{
|
use crate::{glob::Glob, resolution::UnresolvedValue, snapshot::SyncRule};
|
||||||
glob::Glob, resolution::UnresolvedValue, snapshot::SyncRule,
|
|
||||||
snapshot_middleware::default_sync_rules,
|
|
||||||
};
|
|
||||||
|
|
||||||
static PROJECT_FILENAME: &str = "default.project.json";
|
static PROJECT_FILENAME: &str = "default.project.json";
|
||||||
|
|
||||||
@@ -24,6 +21,13 @@ pub struct ProjectError(#[from] Error);
|
|||||||
|
|
||||||
#[derive(Debug, Error)]
|
#[derive(Debug, Error)]
|
||||||
enum Error {
|
enum Error {
|
||||||
|
#[error(
|
||||||
|
"Rojo requires a project file, but no project file was found in path {}\n\
|
||||||
|
See https://rojo.space/docs/ for guides and documentation.",
|
||||||
|
.path.display()
|
||||||
|
)]
|
||||||
|
NoProjectFound { path: PathBuf },
|
||||||
|
|
||||||
#[error("The folder for the provided project cannot be used as a project name: {}\n\
|
#[error("The folder for the provided project cannot be used as a project name: {}\n\
|
||||||
Consider setting the `name` field on this project.", .path.display())]
|
Consider setting the `name` field on this project.", .path.display())]
|
||||||
FolderNameInvalid { path: PathBuf },
|
FolderNameInvalid { path: PathBuf },
|
||||||
@@ -222,7 +226,13 @@ impl Project {
|
|||||||
fuzzy_project_location: &Path,
|
fuzzy_project_location: &Path,
|
||||||
) -> Result<Option<Self>, ProjectError> {
|
) -> Result<Option<Self>, ProjectError> {
|
||||||
if let Some(project_path) = Self::locate(fuzzy_project_location) {
|
if let Some(project_path) = Self::locate(fuzzy_project_location) {
|
||||||
let contents = vfs.read(&project_path).map_err(Error::from)?;
|
let contents = vfs.read(&project_path).map_err(|e| match e.kind() {
|
||||||
|
io::ErrorKind::NotFound => Error::NoProjectFound {
|
||||||
|
path: project_path.to_path_buf(),
|
||||||
|
},
|
||||||
|
_ => return e.into(),
|
||||||
|
})?;
|
||||||
|
|
||||||
Ok(Some(Self::load_from_slice(&contents, project_path, None)?))
|
Ok(Some(Self::load_from_slice(&contents, project_path, None)?))
|
||||||
} else {
|
} else {
|
||||||
Ok(None)
|
Ok(None)
|
||||||
@@ -236,7 +246,13 @@ impl Project {
|
|||||||
fallback_name: Option<&str>,
|
fallback_name: Option<&str>,
|
||||||
) -> Result<Self, ProjectError> {
|
) -> Result<Self, ProjectError> {
|
||||||
let project_path = project_file_location.to_path_buf();
|
let project_path = project_file_location.to_path_buf();
|
||||||
let contents = vfs.read(&project_path).map_err(Error::from)?;
|
let contents = vfs.read(&project_path).map_err(|e| match e.kind() {
|
||||||
|
io::ErrorKind::NotFound => Error::NoProjectFound {
|
||||||
|
path: project_path.to_path_buf(),
|
||||||
|
},
|
||||||
|
_ => return e.into(),
|
||||||
|
})?;
|
||||||
|
|
||||||
Ok(Self::load_from_slice(
|
Ok(Self::load_from_slice(
|
||||||
&contents,
|
&contents,
|
||||||
project_path,
|
project_path,
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ use std::{
|
|||||||
collections::HashSet,
|
collections::HashSet,
|
||||||
io,
|
io,
|
||||||
net::IpAddr,
|
net::IpAddr,
|
||||||
path::{Path, PathBuf},
|
path::Path,
|
||||||
sync::{Arc, Mutex, MutexGuard},
|
sync::{Arc, Mutex, MutexGuard},
|
||||||
time::Instant,
|
time::Instant,
|
||||||
};
|
};
|
||||||
@@ -109,14 +109,7 @@ impl ServeSession {
|
|||||||
|
|
||||||
log::debug!("Loading project file from {}", project_path.display());
|
log::debug!("Loading project file from {}", project_path.display());
|
||||||
|
|
||||||
let root_project = match Project::load_exact(&vfs, &project_path, None) {
|
let root_project = Project::load_exact(&vfs, &project_path, None)?;
|
||||||
Ok(project) => project,
|
|
||||||
Err(_) => {
|
|
||||||
return Err(ServeSessionError::NoProjectFound {
|
|
||||||
path: project_path.to_path_buf(),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut tree = RojoTree::new(InstanceSnapshot::new());
|
let mut tree = RojoTree::new(InstanceSnapshot::new());
|
||||||
|
|
||||||
@@ -226,13 +219,6 @@ impl ServeSession {
|
|||||||
|
|
||||||
#[derive(Debug, Error)]
|
#[derive(Debug, Error)]
|
||||||
pub enum ServeSessionError {
|
pub enum ServeSessionError {
|
||||||
#[error(
|
|
||||||
"Rojo requires a project file, but no project file was found in path {}\n\
|
|
||||||
See https://rojo.space/docs/ for guides and documentation.",
|
|
||||||
.path.display()
|
|
||||||
)]
|
|
||||||
NoProjectFound { path: PathBuf },
|
|
||||||
|
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
Io {
|
Io {
|
||||||
#[from]
|
#[from]
|
||||||
|
|||||||
Reference in New Issue
Block a user