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

Require Errors to be Debug + Display #10

Merged
merged 1 commit into from
Dec 18, 2024
Merged

Conversation

schneems
Copy link
Owner

One goal of this library is to provide a clean interface for other libraries. Errors need to be visible to be useful, it's common that they are required to be Debug + Display. Without these requirements here, they must be added to downstream libraries APIs which is gnarly. For example:

pub(crate) fn cached_layer_write_metadata<M, B>(
    layer_name: LayerName,
    context: &BuildContext<B>,
    metadata: &'_ M,
) -> libcnb::Result<LayerRef<B, Meta<M>, Meta<M>>, B::Error>
where
    B: libcnb::Buildpack,
    M: CacheDiff + TryMigrate + Serialize
    <M as TryMigrate>::Error: std::fmt::Display, // <=== HERE
{
    // ...
}

With this change applied it should allow applications to remove that extra qualification:

pub(crate) fn cached_layer_write_metadata<M, B>(
    layer_name: LayerName,
    context: &BuildContext<B>,
    metadata: &'_ M,
) -> libcnb::Result<LayerRef<B, Meta<M>, Meta<M>>, B::Error>
where
    B: libcnb::Buildpack,
    M: CacheDiff + TryMigrate + Serialize
    // Much cleaner now!
{
    // ...
}

This is an API change, so it's a major version rev. Though most (if not all) consumers would be using this with errors that are already Debug + Display.

One goal of this library is to provide a clean interface for other libraries. Errors need to be visible to be useful, it's common that they are required to be Debug + Display. Without these requirements here, they must be added to downstream libraries APIs which is gnarly. For example:

```rust
pub(crate) fn cached_layer_write_metadata<M, B>(
    layer_name: LayerName,
    context: &BuildContext<B>,
    metadata: &'_ M,
) -> libcnb::Result<LayerRef<B, Meta<M>, Meta<M>>, B::Error>
where
    B: libcnb::Buildpack,
    M: CacheDiff + TryMigrate + Serialize
    <M as TryMigrate>::Error: std::fmt::Display, // <=== HERE
{
    // ...
}
```

With this change applied it should allow applications to remove that extra qualification:

```rust
pub(crate) fn cached_layer_write_metadata<M, B>(
    layer_name: LayerName,
    context: &BuildContext<B>,
    metadata: &'_ M,
) -> libcnb::Result<LayerRef<B, Meta<M>, Meta<M>>, B::Error>
where
    B: libcnb::Buildpack,
    M: CacheDiff + TryMigrate + Serialize
    // Much cleaner now!
{
    // ...
}
```

This is an API change, so it's a major version rev. Though most (if not all) consumers would be using this with errors that are already Debug + Display.
@schneems schneems merged commit aaea1f0 into main Dec 18, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant