-
Notifications
You must be signed in to change notification settings - Fork 47
Open
Description
omicron/common/src/api/external/mod.rs
Lines 1968 to 1994 in 80e9922
impl FromStr for L4PortRange { | |
type Err = String; | |
fn from_str(range: &str) -> Result<Self, Self::Err> { | |
const INVALID_PORT_NUMBER_MSG: &str = "invalid port number"; | |
match range.split_once('-') { | |
None => { | |
let port = range | |
.parse::<NonZeroU16>() | |
.map_err(|_| INVALID_PORT_NUMBER_MSG.to_string())? | |
.into(); | |
Ok(L4PortRange { first: port, last: port }) | |
} | |
Some((left, right)) => { | |
let first = left | |
.parse::<NonZeroU16>() | |
.map_err(|_| INVALID_PORT_NUMBER_MSG.to_string())? | |
.into(); | |
let last = right | |
.parse::<NonZeroU16>() | |
.map_err(|_| INVALID_PORT_NUMBER_MSG.to_string())? | |
.into(); | |
Ok(L4PortRange { first, last }) | |
} | |
} | |
} | |
} |
The FromStr
impl
s in our external API mostly return String
s with some anyhow::Error
s. We could converge on omicron_common::api::external::Error::InvalidValue
instead, to give a little more context where more complex strings are handled.
#8194 converts the types used in firewall rules to this errorkind, but we could maybe go further here. Most of the types here have straightforward parsing, but types like Digest
might benefit since they apply a similar tag:value
pattern.
hawkw
Metadata
Metadata
Assignees
Labels
No labels