file: Always return glib::Error with domain gst::URIError from set_uri()

This commit is contained in:
Sebastian Dröge 2018-12-30 12:02:28 +02:00
parent e77c23352a
commit bab4efb234
3 changed files with 8 additions and 8 deletions

View file

@ -49,14 +49,14 @@ impl FileLocation {
fn try_from(location: PathBuf) -> Result<Self, glib::Error> {
let location_str = location.to_str().ok_or_else(|| {
gst::Error::new(
gst::LibraryError::Failed,
gst::URIError::BadReference,
format!("Invalid path {:?}", location).as_str(),
)
})?;
let file_name = location.file_name().ok_or_else(|| {
gst::Error::new(
gst::LibraryError::Failed,
gst::URIError::BadReference,
format!("Expected a path with a filename, got {}", location_str,).as_str(),
)
})?;
@ -75,7 +75,7 @@ impl FileLocation {
let parent_canonical = parent_dir.canonicalize().map_err(|err| {
gst::Error::new(
gst::LibraryError::Failed,
gst::URIError::BadReference,
format!(
"Could not resolve path {}: {}",
location_str,
@ -106,7 +106,7 @@ impl FileLocation {
Url::from_file_path(&location_canonical)
.map_err(|_| {
gst::Error::new(
gst::LibraryError::Failed,
gst::URIError::BadReference,
format!("Could not resolve path to URL {}", location_str).as_str(),
)
})

View file

@ -76,7 +76,7 @@ impl FileSink {
let state = self.state.lock().unwrap();
if let State::Started { .. } = *state {
return Err(gst::Error::new(
gst::LibraryError::Failed,
gst::URIError::BadState,
"Changing the `location` property on a started `filesink` is not supported",
));
}

View file

@ -75,7 +75,7 @@ impl FileSrc {
let state = self.state.lock().unwrap();
if let State::Started { .. } = *state {
return Err(gst::Error::new(
gst::LibraryError::Failed,
gst::URIError::BadState,
"Changing the `location` property on a started `filesrc` is not supported",
));
}
@ -85,14 +85,14 @@ impl FileSrc {
Some(location) => {
if !location.exists() {
return Err(gst::Error::new(
gst::LibraryError::Failed,
gst::URIError::BadReference,
format!("{} doesn't exist", location).as_str(),
));
}
if !location.is_file() {
return Err(gst::Error::new(
gst::LibraryError::Failed,
gst::URIError::BadReference,
format!("{} is not a file", location).as_str(),
));
}