Przeglądaj źródła

More detailed error type for Url::set_host

Simon Sapin 10 lat temu
rodzic
commit
e4035794b0
2 zmienionych plików z 4 dodań i 3 usunięć
  1. 3 3
      src/lib.rs
  2. 1 0
      src/parser.rs

+ 3 - 3
src/lib.rs

@@ -825,13 +825,13 @@ impl Url {
     ///
     /// Removing the host (calling this with `None`)
     /// will also remove any username, password, and port number.
-    pub fn set_host(&mut self, host: Option<&str>) -> Result<(), ()> {
+    pub fn set_host(&mut self, host: Option<&str>) -> Result<(), ParseError> {
         if self.cannot_be_a_base() {
-            return Err(())
+            return Err(ParseError::SetHostOnCannotBeABaseUrl)
         }
 
         if let Some(host) = host {
-            self.set_host_internal(try!(Host::parse(host).map_err(|_| ())), None)
+            self.set_host_internal(try!(Host::parse(host)), None)
         } else if self.has_host() {
             debug_assert!(self.byte_at(self.scheme_end) == b':');
             debug_assert!(self.byte_at(self.path_start) == b'/');

+ 1 - 0
src/parser.rs

@@ -52,6 +52,7 @@ simple_enum_error! {
     InvalidDomainCharacter => "invalid domain character",
     RelativeUrlWithoutBase => "relative URL without a base",
     RelativeUrlWithCannotBeABaseBase => "relative URL with a cannot-be-a-base base",
+    SetHostOnCannotBeABaseUrl => "a cannot-be-a-base URL doesn’t have a host to set",
     Overflow => "URLs more than 4 GB are not supported",
 }