Skip to content

Commit

Permalink
Rename OpenWorkspaceByPathError to OpenWorkspaceError
Browse files Browse the repository at this point in the history
Use Option<T> functions instead of doing it manually
  • Loading branch information
hatchan committed Sep 24, 2024
1 parent 9363123 commit 15751b5
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 13 deletions.
14 changes: 6 additions & 8 deletions fpx-app/src/commands/workspace.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::models::workspace::{OpenWorkspaceByPathError, Workspace};
use crate::models::workspace::{OpenWorkspaceError, Workspace};
use crate::state::AppState;
use crate::STORE_PATH;
use fpx::config::{FpxConfig, FpxConfigError};
Expand Down Expand Up @@ -40,19 +40,17 @@ pub fn open_workspace_by_path<R: Runtime>(
state: State<'_, AppState>,
app: AppHandle<R>,
stores: State<'_, StoreCollection<R>>,
) -> Result<Workspace, OpenWorkspaceByPathError> {
) -> Result<Workspace, OpenWorkspaceError> {
let path_buf = PathBuf::from(path.clone());
let config = match FpxConfig::load(Some(path_buf)) {
Ok((config, _config_path)) => config,
Err(err) => {
return Err(match err {
FpxConfigError::FileNotFound(path_buf) => {
OpenWorkspaceByPathError::ConfigFileMissing {
path: path_buf.to_string_lossy().to_string(),
}
}
FpxConfigError::FileNotFound(path_buf) => OpenWorkspaceError::ConfigFileMissing {
path: path_buf.to_string_lossy().to_string(),
},
FpxConfigError::InvalidFpxConfig { message, .. } => {
OpenWorkspaceByPathError::InvalidConfiguration { message }
OpenWorkspaceError::InvalidConfiguration { message }
}
FpxConfigError::RootDirectoryNotFound => {
unreachable!("FpxConfig::load takes a path, so this cannot occur")
Expand Down
2 changes: 1 addition & 1 deletion fpx-app/src/models/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ impl Workspace {

#[derive(JsonSchema, Deserialize, Serialize)]
#[serde(tag = "type")]
pub enum OpenWorkspaceByPathError {
pub enum OpenWorkspaceError {
ConfigFileMissing { path: String },
InvalidConfiguration { message: String },
}
6 changes: 3 additions & 3 deletions fpx-app/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ pub struct AppState {
impl AppState {
pub fn set_workspace(&self, workspace: Workspace) {
let mut workspace_lock = self.workspace.lock().unwrap();
*workspace_lock = Some(workspace);
workspace_lock.replace(workspace);
}

pub fn close_workspace(&self) {
let mut workspace_lock = self.workspace.lock().unwrap();
*workspace_lock = None;
workspace_lock.take();
}

pub fn get_workspace(&self) -> Option<Workspace> {
let workspace_lock = self.workspace.lock().unwrap();
workspace_lock.as_ref().map(|workspace| workspace.clone())
workspace_lock.as_ref().cloned()
}
}
2 changes: 1 addition & 1 deletion xtask/src/commands/schemas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub async fn handle_command(args: Args) -> Result<()> {
schema_for!(ClientMessage),
schema_for!(ServerMessage),
schema_for!(fpx_app::state::AppState),
schema_for!(fpx_app::models::workspace::OpenWorkspaceByPathError),
schema_for!(fpx_app::models::workspace::OpenWorkspaceError),
schema_for!(fpx_app::models::workspace::Workspace),
schema_for!(fpx::config::FpxConfig),
schema_for!(fpx::config::FpxConfigError),
Expand Down

0 comments on commit 15751b5

Please sign in to comment.