Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix returning NoProjectFound for any project load error #985

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 22 additions & 6 deletions src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ use memofs::Vfs;
use serde::{Deserialize, Serialize};
use thiserror::Error;

use crate::{
glob::Glob, resolution::UnresolvedValue, snapshot::SyncRule,
snapshot_middleware::default_sync_rules,
};
use crate::{glob::Glob, resolution::UnresolvedValue, snapshot::SyncRule};

static PROJECT_FILENAME: &str = "default.project.json";

Expand All @@ -24,6 +21,13 @@ pub struct ProjectError(#[from] Error);

#[derive(Debug, 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\
Consider setting the `name` field on this project.", .path.display())]
FolderNameInvalid { path: PathBuf },
Expand Down Expand Up @@ -222,7 +226,13 @@ impl Project {
fuzzy_project_location: &Path,
) -> Result<Option<Self>, ProjectError> {
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)?))
} else {
Ok(None)
Expand All @@ -236,7 +246,13 @@ impl Project {
fallback_name: Option<&str>,
) -> Result<Self, ProjectError> {
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(
&contents,
project_path,
Expand Down
18 changes: 2 additions & 16 deletions src/serve_session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::{
collections::HashSet,
io,
net::IpAddr,
path::{Path, PathBuf},
path::Path,
sync::{Arc, Mutex, MutexGuard},
time::Instant,
};
Expand Down Expand Up @@ -109,14 +109,7 @@ impl ServeSession {

log::debug!("Loading project file from {}", project_path.display());

let root_project = match Project::load_exact(&vfs, &project_path, None) {
Ok(project) => project,
Err(_) => {
return Err(ServeSessionError::NoProjectFound {
path: project_path.to_path_buf(),
})
}
};
let root_project = Project::load_exact(&vfs, &project_path, None)?;

let mut tree = RojoTree::new(InstanceSnapshot::new());

Expand Down Expand Up @@ -226,13 +219,6 @@ impl ServeSession {

#[derive(Debug, Error)]
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)]
Io {
#[from]
Expand Down
Loading