import strategy for error module (cont.)
This commit is contained in:
parent
e3fc06b019
commit
357f455ec0
1 changed files with 4 additions and 6 deletions
|
|
@ -4,8 +4,6 @@ use log::{debug, trace};
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::error;
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||||
pub struct AliasID(String);
|
pub struct AliasID(String);
|
||||||
|
|
||||||
|
|
@ -52,9 +50,9 @@ impl fmt::Display for FileID {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryFrom<String> for FileID {
|
impl TryFrom<String> for FileID {
|
||||||
type Error = error::Error;
|
type Error = crate::Error;
|
||||||
|
|
||||||
fn try_from(value: String) -> error::Result<Self> {
|
fn try_from(value: String) -> crate::Result<Self> {
|
||||||
/// Pattern breakdown:
|
/// Pattern breakdown:
|
||||||
/// - `^([^:/?#]+)://` – scheme (anything but `:/?#`) + `"://"`
|
/// - `^([^:/?#]+)://` – scheme (anything but `:/?#`) + `"://"`
|
||||||
/// - `([^/?#]+)` – authority/host (anything but `/?#`)
|
/// - `([^/?#]+)` – authority/host (anything but `/?#`)
|
||||||
|
|
@ -83,7 +81,7 @@ impl TryFrom<String> for FileID {
|
||||||
|
|
||||||
Ok(result)
|
Ok(result)
|
||||||
} else {
|
} else {
|
||||||
Err(error::Error::mismatch(
|
Err(crate::Error::mismatch(
|
||||||
"<proto>://<base>/api/v2/alias/upload/<share>/files/tus/<file>",
|
"<proto>://<base>/api/v2/alias/upload/<share>/files/tus/<file>",
|
||||||
value,
|
value,
|
||||||
))
|
))
|
||||||
|
|
@ -143,7 +141,7 @@ mod tests {
|
||||||
let err = FileID::try_from(bad.to_string()).expect_err("URL should not parse");
|
let err = FileID::try_from(bad.to_string()).expect_err("URL should not parse");
|
||||||
// make sure it's the Mismatch variant, and that it contains the original input
|
// make sure it's the Mismatch variant, and that it contains the original input
|
||||||
match err {
|
match err {
|
||||||
error::Error::Mismatch { expected, actual } => {
|
crate::Error::Mismatch { expected, actual } => {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
expected, "<proto>://<base>/api/v2/alias/upload/<share>/files/tus/<file>",
|
expected, "<proto>://<base>/api/v2/alias/upload/<share>/files/tus/<file>",
|
||||||
"Error should output expected format"
|
"Error should output expected format"
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue