-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make features explicit, error fixes,
* Use `thiserror` for all errors to allow better error reporting * Make all HTTP errors into proper objects without string formatting -- formatting is delayed until printing, or if not logged by end user, works much faster * add justfile to simplify development (optional, but useful) * cleanup CI to make it far simpler (that GH action is not maintained, and not worth it) * Made cargo.toml explicitly declare all features - instead of auto-exposing optional dependencies as features * Lastly, it seems `fmmap` has not been updated for a long time, and because of that it no longer compiles in some cases because of the dependency problems. I submitted a PR, hopefully will be merged/published soonish.
- Loading branch information
Showing
8 changed files
with
133 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#!/usr/bin/env just --justfile | ||
|
||
@_default: | ||
just --list --unsorted | ||
|
||
# Run all tests | ||
test: | ||
# These are the same tests that are run on CI. Eventually CI should just call into justfile | ||
cargo check | ||
rustup component add clippy rustfmt | ||
cargo fmt --all -- --check | ||
cargo clippy --all-targets --all-features -- -D warnings | ||
cargo test --all-targets --all-features | ||
cargo test --features http-async | ||
cargo test --features mmap-async-tokio | ||
cargo test --features tilejson | ||
RUSTDOCFLAGS="-D warnings" cargo doc --no-deps | ||
|
||
# Run cargo fmt and cargo clippy | ||
lint: fmt clippy | ||
|
||
# Run cargo fmt | ||
fmt: | ||
cargo +nightly fmt -- --config imports_granularity=Module,group_imports=StdExternalCrate | ||
|
||
# Run cargo clippy | ||
clippy: | ||
cargo clippy --workspace --all-targets --bins --tests --lib --benches -- -D warnings | ||
|
||
# Build and open code documentation | ||
docs: | ||
cargo doc --no-deps --open | ||
|
||
# Clean all build artifacts | ||
clean: | ||
cargo clean | ||
rm -f Cargo.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,53 @@ | ||
use std::string::FromUtf8Error; | ||
|
||
#[derive(Debug)] | ||
// use std::string::FromUtf8Error; | ||
use thiserror::Error; | ||
|
||
#[derive(Debug, Error)] | ||
pub enum Error { | ||
#[error("Invalid magic number")] | ||
InvalidMagicNumber, | ||
#[error("Invalid PMTiles version")] | ||
UnsupportedPmTilesVersion, | ||
#[error("Invalid compression")] | ||
InvalidCompression, | ||
#[error("Invalid PMTiles entry")] | ||
InvalidEntry, | ||
#[error("Invalid header")] | ||
InvalidHeader, | ||
#[error("Invalid metadata")] | ||
InvalidMetadata, | ||
#[error("Invalid metadata UTF-8 encoding: {0}")] | ||
InvalidMetadataUtf8Encoding(#[from] FromUtf8Error), | ||
#[error("Invalid tile type")] | ||
InvalidTileType, | ||
Reading(std::io::Error), | ||
#[cfg(feature = "fmmap")] | ||
#[error("IO Error {0}")] | ||
Reading(#[from] std::io::Error), | ||
#[cfg(feature = "mmap-async-tokio")] | ||
#[error("Unable to open mmap file")] | ||
UnableToOpenMmapFile, | ||
Http(String), | ||
#[cfg(feature = "http-async")] | ||
#[error("{0}")] | ||
Http(#[from] HttpError), | ||
} | ||
|
||
impl From<std::io::Error> for Error { | ||
fn from(e: std::io::Error) -> Self { | ||
Self::Reading(e) | ||
} | ||
#[cfg(feature = "http-async")] | ||
#[derive(Debug, Error)] | ||
pub enum HttpError { | ||
#[error("Unexpected number of bytes returned [expected: {0}, received: {1}].")] | ||
UnexpectedNumberOfBytesReturned(usize, usize), | ||
#[error("Range requests unsupported")] | ||
RangeRequestsUnsupported, | ||
#[error("HTTP response body is too long, Response {0}B > requested {1}B")] | ||
ResponseBodyTooLong(usize, usize), | ||
#[error("HTTP error {0}")] | ||
Http(#[from] reqwest::Error), | ||
} | ||
|
||
impl From<FromUtf8Error> for Error { | ||
fn from(_: FromUtf8Error) -> Self { | ||
Self::InvalidMetadata | ||
// This is required because thiserror #[from] does not support two-level conversion. | ||
#[cfg(feature = "http-async")] | ||
impl From<reqwest::Error> for Error { | ||
fn from(e: reqwest::Error) -> Self { | ||
Self::Http(HttpError::Http(e)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters