Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: better error reporting when getting #670

Merged
merged 3 commits into from
Mar 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/api/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

- kwargs to Python search build ([#591](https://github.com/stac-utils/stac-rs/pull/591))
- `client::search` function ([#607](https://github.com/stac-utils/stac-rs/pull/607))
- Better error reporting from `get` ([#670](https://github.com/stac-utils/stac-rs/pull/670))

## [0.7.0] - 2025-01-02

Expand Down
12 changes: 11 additions & 1 deletion crates/core/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::Version;
use crate::{Href, Version};
use thiserror::Error;

/// Error enum for crate-specific errors.
Expand Down Expand Up @@ -43,6 +43,16 @@ pub enum Error {
#[error(transparent)]
Geojson(#[from] Box<geojson::Error>),

/// An error occurred when getting an href.
#[error("error when getting href={href}: {message}")]
Get {
/// The href that we were trying to get.
href: Href,

/// The underling error message.
message: String,
},

/// [std::io::Error]
#[error(transparent)]
Io(#[from] std::io::Error),
Expand Down
19 changes: 16 additions & 3 deletions crates/core/src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,17 +156,30 @@ impl Format {
V: Into<String>,
{
let href = href.into();
match href.realize() {
match href.clone().realize() {
RealizedHref::Url(url) => {
use object_store::ObjectStore;

let (object_store, path) = parse_url_opts(&url, options)?;
let get_result = object_store.get(&path).await?;
tracing::debug!("getting {self} from {url} with object store");
let get_result = object_store.get(&path).await.map_err(|err| Error::Get {
href,
message: err.to_string(),
})?;
let mut value: T = self.from_bytes(get_result.bytes().await?)?;
*value.self_href_mut() = Some(Href::Url(url));
Ok(value)
}
RealizedHref::PathBuf(path) => self.from_path(path),
RealizedHref::PathBuf(path) => {
tracing::debug!(
"getting {self} from {} with the standard library",
path.display()
);
self.from_path(path).map_err(|err| Error::Get {
href,
message: err.to_string(),
})
}
}
}

Expand Down