Skip to content
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
10 changes: 6 additions & 4 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ stable_test_task:
- cargo test --manifest-path compatibility-tests/alloc-only/Cargo.toml
backtraces_impl_backtrace_crate_test_script:
- cargo test --manifest-path compatibility-tests/backtraces-impl-backtrace-crate/Cargo.toml
backtraces_impl_inert_test_script:
- cargo test --manifest-path compatibility-tests/backtraces-impl-inert/Cargo.toml
context_selectors_have_documentation_test_script:
- cargo test --manifest-path compatibility-tests/context-selectors-have-documentation/Cargo.toml
renamed_import_test_script:
Expand Down Expand Up @@ -185,18 +187,18 @@ nightly_test_task:
before_cache_script: rm -rf $CARGO_HOME/registry/index

# Our Minimal Supported Rust Version (MSRV)
v1_61_test_task:
name: "Rust 1.61"
v1_65_test_task:
name: "Rust 1.65"
container:
image: rust:1.61
image: rust:1.65
cpu: 1
memory: 2Gi
cargo_cache:
folder: $CARGO_HOME/registry
fingerprint_script: cat Cargo.toml
primary_test_script:
- rustup self update
- cd compatibility-tests/v1_61/
- cd compatibility-tests/v1_65/
- rustc --version
- cargo test
before_cache_script: rm -rf $CARGO_HOME/registry/index
9 changes: 3 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "snafu"
version = "0.8.9"
authors = ["Jake Goulding <[email protected]>"]
edition = "2018"
rust-version = "1.61"
rust-version = "1.65"

readme = "README.md"
description = "An ergonomic error handling library"
Expand All @@ -29,7 +29,7 @@ exclude = [
features = ["futures", "guide"]

[features]
default = ["std", "rust_1_65"]
default = ["std"]

# Implement the `std::error::Error` trait.
std = ["alloc"]
Expand All @@ -40,11 +40,8 @@ alloc = []
# Implement the `core::error::Error` trait.
unstable-core-error = []

# `Backtrace` was stabilized
rust_1_65 = []

# `core::error` was stabilized
rust_1_81 = ["rust_1_65"]
rust_1_81 = []

# The backtrace type becomes `backtrace::Backtrace`
backtraces-impl-backtrace-crate = ["backtrace"]
Expand Down
7 changes: 7 additions & 0 deletions compatibility-tests/backtraces-impl-inert/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "backtraces-impl-inert"
version = "0.1.0"
edition = "2024"

[dependencies]
snafu = { path = "../../", default-features = false }
59 changes: 59 additions & 0 deletions compatibility-tests/backtraces-impl-inert/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#![cfg(test)]

use snafu::{Backtrace, ErrorCompat, prelude::*};

#[derive(Debug, Snafu)]
struct AnotherError;

#[derive(Debug, Snafu)]
enum Error {
#[snafu(display("Invalid user {user_id}:\n{backtrace}"))]
InvalidUser { user_id: i32, backtrace: Backtrace },
WithSource {
source: AnotherError,
backtrace: Backtrace,
},
WithSourceAndOtherInfo {
user_id: i32,
source: AnotherError,
backtrace: Backtrace,
},
}

type Result<T, E = Error> = std::result::Result<T, E>;

fn example(user_id: i32) -> Result<()> {
ensure!(user_id >= 42, InvalidUserSnafu { user_id });
Ok(())
}

#[test]
fn display_can_access_backtrace() {
let e = example(0).unwrap_err();
let text = e.to_string();
assert!(
text.contains("disabled backtrace"),
"{:?} does not contain expected text",
text
);
}

fn trigger() -> Result<(), AnotherError> {
Err(AnotherError)
}

#[test]
fn errors_with_sources_can_have_backtraces() {
let e = trigger().context(WithSourceSnafu).unwrap_err();
let backtrace = ErrorCompat::backtrace(&e).unwrap();
assert!(backtrace.to_string().contains("disabled backtrace"));
}

#[test]
fn errors_with_sources_and_other_info_can_have_backtraces() {
let e = trigger()
.context(WithSourceAndOtherInfoSnafu { user_id: 42 })
.unwrap_err();
let backtrace = ErrorCompat::backtrace(&e).unwrap();
assert!(backtrace.to_string().contains("disabled backtrace"));
}
1 change: 0 additions & 1 deletion compatibility-tests/v1_61/rust-toolchain

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[package]
name = "v1_61"
name = "v1_65"
version = "0.1.0"
authors = ["Jake Goulding <[email protected]>"]
edition = "2018"
rust-version = "1.61"
rust-version = "1.65"

[dependencies]
snafu = { path = "../..", default-features = false, features = ["std"] }

# These versions are the last versions to support Rust 1.61
# These versions are the last versions to support Rust 1.65
quote = { version = "=1.0.41", default-features = false }
syn = { version = "=2.0.106", default-features = false }
1 change: 1 addition & 0 deletions compatibility-tests/v1_65/rust-toolchain
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.65
Original file line number Diff line number Diff line change
Expand Up @@ -108,60 +108,3 @@ mod core_functionality {
}
}
}

use snafu::{prelude::*, Backtrace, ErrorCompat};

type AnotherError = Box<dyn std::error::Error>;

#[derive(Debug, Snafu)]
enum Error {
#[snafu(display("Invalid user {}:\n{}", user_id, backtrace))]
InvalidUser { user_id: i32, backtrace: Backtrace },
WithSource {
source: AnotherError,
backtrace: Backtrace,
},
WithSourceAndOtherInfo {
user_id: i32,
source: AnotherError,
backtrace: Backtrace,
},
}

type Result<T, E = Error> = std::result::Result<T, E>;

fn example(user_id: i32) -> Result<()> {
ensure!(user_id >= 42, InvalidUserSnafu { user_id });
Ok(())
}

#[test]
fn display_can_access_backtrace() {
let e = example(0).unwrap_err();
let text = e.to_string();
assert!(
text.contains("disabled backtrace"),
"{:?} does not contain expected text",
text
);
}

fn trigger() -> Result<(), AnotherError> {
Err("boom".into())
}

#[test]
fn errors_with_sources_can_have_backtraces() {
let e = trigger().context(WithSourceSnafu).unwrap_err();
let backtrace = ErrorCompat::backtrace(&e).unwrap();
assert!(backtrace.to_string().contains("disabled backtrace"));
}

#[test]
fn errors_with_sources_and_other_info_can_have_backtraces() {
let e = trigger()
.context(WithSourceAndOtherInfoSnafu { user_id: 42 })
.unwrap_err();
let backtrace = ErrorCompat::backtrace(&e).unwrap();
assert!(backtrace.to_string().contains("disabled backtrace"));
}
2 changes: 1 addition & 1 deletion snafu-derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "snafu-derive"
version = "0.8.9"
authors = ["Jake Goulding <[email protected]>"]
edition = "2018"
rust-version = "1.61"
rust-version = "1.65"

description = "An ergonomic error handling library"
documentation = "https://docs.rs/snafu"
Expand Down
8 changes: 2 additions & 6 deletions snafu-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,18 +99,14 @@ impl ContextSelectorName {
}
}

#[derive(Default)]
enum SuffixKind {
#[default]
Default,
None,
Some(syn::Ident),
}

impl Default for SuffixKind {
fn default() -> Self {
SuffixKind::Default
}
}

impl SuffixKind {
const DEFAULT_SUFFIX: &'static str = "Snafu";

Expand Down
24 changes: 2 additions & 22 deletions src/guide/compatibility.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## Rust version compatibility

SNAFU is tested and compatible back to Rust 1.61, released on
2022-05-19. Compatibility is controlled by Cargo feature flags.
SNAFU is tested and compatible back to Rust 1.65, released on
2022-11-03. Compatibility is controlled by Cargo feature flags.

<style>
.snafu-ff-meta>dt {
Expand All @@ -12,31 +12,11 @@ SNAFU is tested and compatible back to Rust 1.61, released on
}
</style>

## `rust_1_65`

<dl class="snafu-ff-meta">
<dt>Default</dt>
<dd>enabled</dd>
</dl>

When enabled, SNAFU will assume that it's safe to target features
available in Rust 1.65. Notably, the [`Backtrace`][] type is used when
the standard library is available and no other backtrace provider is
selected.

[`Backtrace`]: std::backtrace::Backtrace

## `rust_1_81`

<dl class="snafu-ff-meta">
<dt>Default</dt>
<dd>disabled</dd>
<dt>Implies</dt>
<dd>

[`rust_1_65`](#rust_1_65)

</dd>
</dl>

When enabled, SNAFU will assume that it's safe to target features
Expand Down
11 changes: 2 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,22 +295,15 @@ pub mod prelude {
pub use crate::futures::{TryFutureExt as _, TryStreamExt as _};
}

#[cfg(not(any(
all(feature = "std", feature = "rust_1_65"),
feature = "backtraces-impl-backtrace-crate"
)))]
#[cfg(not(any(feature = "std", feature = "backtraces-impl-backtrace-crate")))]
#[path = "backtrace_impl_inert.rs"]
mod backtrace_impl;

#[cfg(feature = "backtraces-impl-backtrace-crate")]
#[path = "backtrace_impl_backtrace_crate.rs"]
mod backtrace_impl;

#[cfg(all(
feature = "std",
feature = "rust_1_65",
not(feature = "backtraces-impl-backtrace-crate")
))]
#[cfg(all(feature = "std", not(feature = "backtraces-impl-backtrace-crate")))]
#[path = "backtrace_impl_std.rs"]
mod backtrace_impl;

Expand Down