Skip to content

Commit acb84d8

Browse files
committed
Move to HostParseError
1 parent 4fb9d50 commit acb84d8

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

crates/stackable-operator/src/commons/networking.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::{fmt::Display, net::IpAddr, ops::Deref, str::FromStr};
22

33
use schemars::JsonSchema;
44
use serde::{Deserialize, Serialize};
5+
use snafu::Snafu;
56

67
use crate::validation;
78

@@ -49,6 +50,14 @@ impl Deref for Hostname {
4950
}
5051
}
5152

53+
#[derive(Debug, Snafu)]
54+
pub enum HostParseError {
55+
#[snafu(display(
56+
"the given host '{host}' is not a valid host, which needs to be either a hostname or IP address"
57+
))]
58+
InvalidHost { host: String },
59+
}
60+
5261
/// A validated host (either a [`Hostname`] or IP address) type.
5362
#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)]
5463
#[serde(try_from = "String", into = "String")]
@@ -68,7 +77,7 @@ impl JsonSchema for Host {
6877
}
6978

7079
impl FromStr for Host {
71-
type Err = validation::Error;
80+
type Err = HostParseError;
7281

7382
fn from_str(value: &str) -> Result<Self, Self::Err> {
7483
if let Ok(ip) = value.parse::<IpAddr>() {
@@ -79,14 +88,15 @@ impl FromStr for Host {
7988
return Ok(Host::Hostname(hostname));
8089
};
8190

82-
Err(validation::Error::InvalidHost {
91+
InvalidHostSnafu {
8392
host: value.to_owned(),
84-
})
93+
}
94+
.fail()
8595
}
8696
}
8797

8898
impl TryFrom<String> for Host {
89-
type Error = validation::Error;
99+
type Error = HostParseError;
90100

91101
fn try_from(value: String) -> Result<Self, Self::Error> {
92102
value.parse()

crates/stackable-operator/src/validation.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,6 @@ pub enum Error {
9090

9191
#[snafu(display("input is {length} bytes long but must be no more than {max_length}"))]
9292
TooLong { length: usize, max_length: usize },
93-
94-
#[snafu(display(
95-
"The input '{host}' is not a valid host, which needs to be either a hostname or IP address"
96-
))]
97-
InvalidHost { host: String },
9893
}
9994

10095
#[derive(Debug)]

0 commit comments

Comments
 (0)