-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: handle parsing filename errors
- Loading branch information
1 parent
5bd1585
commit 8f7cda3
Showing
6 changed files
with
87 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,20 @@ | ||
use anyhow::Result; | ||
use anyhow::{bail, Result}; | ||
|
||
use crate::errors::SqliteBackupError; | ||
|
||
pub struct Argument { | ||
pub source_path: String, | ||
} | ||
|
||
impl Argument { | ||
pub fn build(args: &[String]) -> Result<Self, &'static str> { | ||
pub fn build(args: &[String]) -> Result<Self> { | ||
if let Some(source_path) = args.get(1) { | ||
let argument = Self { | ||
source_path: source_path.clone(), | ||
}; | ||
Ok(argument) | ||
} else { | ||
Err("No source path provided.") | ||
bail!(SqliteBackupError::NoSourceFileError); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
use std::{error::Error, fmt::Display}; | ||
|
||
#[derive(Debug)] | ||
pub enum SqliteBackupError { | ||
SourceFileError(String), | ||
NoSourceFileError, | ||
} | ||
|
||
impl Error for SqliteBackupError {} | ||
|
||
impl Display for SqliteBackupError { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
match self { | ||
SqliteBackupError::SourceFileError(source) => { | ||
write!(f, "Source file error: {}", source) | ||
} | ||
SqliteBackupError::NoSourceFileError => write!(f, "No source path provided."), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters