Skip to content

Commit 27039f6

Browse files
committed
Change error handling in cidr FromSql implementations
1 parent dd7bc07 commit 27039f6

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

postgres-types/src/cidr_02.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ use crate::{FromSql, IsNull, ToSql, Type};
88
impl<'a> FromSql<'a> for IpCidr {
99
fn from_sql(_: &Type, raw: &[u8]) -> Result<Self, Box<dyn Error + Sync + Send>> {
1010
let inet = types::inet_from_sql(raw)?;
11-
Ok(IpCidr::new(inet.addr(), inet.netmask())
12-
.expect("postgres cidr type has zeroed host portion"))
11+
Ok(IpCidr::new(inet.addr(), inet.netmask())?)
1312
}
1413

1514
accepts!(CIDR);
@@ -28,8 +27,7 @@ impl ToSql for IpCidr {
2827
impl<'a> FromSql<'a> for IpInet {
2928
fn from_sql(_: &Type, raw: &[u8]) -> Result<Self, Box<dyn Error + Sync + Send>> {
3029
let inet = types::inet_from_sql(raw)?;
31-
Ok(IpInet::new(inet.addr(), inet.netmask())
32-
.expect("postgres enforces maximum length of netmask"))
30+
Ok(IpInet::new(inet.addr(), inet.netmask())?)
3331
}
3432

3533
accepts!(INET);

0 commit comments

Comments
 (0)