drop thiserror

This commit is contained in:
Robin Appelman 2025-05-22 17:11:21 +02:00
commit c7439f746d
3 changed files with 19 additions and 66 deletions

58
Cargo.lock generated
View file

@ -2,64 +2,6 @@
# It is not intended for manual editing. # It is not intended for manual editing.
version = 3 version = 3
[[package]]
name = "proc-macro2"
version = "1.0.78"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.35"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef"
dependencies = [
"proc-macro2",
]
[[package]] [[package]]
name = "secretfile" name = "secretfile"
version = "0.1.0" version = "0.1.0"
dependencies = [
"thiserror",
]
[[package]]
name = "syn"
version = "2.0.52"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b699d15b36d1f02c3e7c69f8ffef53de37aefae075d8488d4ba1a7788d574a07"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "thiserror"
version = "1.0.57"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e45bcbe8ed29775f228095caf2cd67af7a4ccf756ebff23a306bf3e8b47b24b"
dependencies = [
"thiserror-impl",
]
[[package]]
name = "thiserror-impl"
version = "1.0.57"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a953cb265bef375dae3de6663da4d3804eee9682ea80d8e2542529b73c531c81"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "unicode-ident"
version = "1.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"

View file

@ -5,6 +5,3 @@ edition = "2021"
description = "A small library for helping with loading secrets from files including systemd service credentials support" description = "A small library for helping with loading secrets from files including systemd service credentials support"
license = "MIT OR Apache-2.0" license = "MIT OR Apache-2.0"
repository = "https://github.com/icewind1991/secretfile" repository = "https://github.com/icewind1991/secretfile"
[dependencies]
thiserror = "1.0.57"

View file

@ -1,16 +1,30 @@
use std::borrow::Cow; use std::borrow::Cow;
use std::env::var; use std::env::var;
use std::error::Error;
use std::fmt::Display;
use std::fs::read_to_string; use std::fs::read_to_string;
use thiserror::Error;
#[derive(Debug, Error)] #[derive(Debug)]
pub enum SecretError { pub enum SecretError {
#[error("failed to load token from {path}: {error:#}")]
Load { path: String, error: std::io::Error }, Load { path: String, error: std::io::Error },
#[error("environment variable {0} referenced but not set")]
MissingEnvVar(String), MissingEnvVar(String),
} }
impl Display for SecretError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
SecretError::Load { path, error } => {
write!(f, "failed to load token from {path}: {error:#}")
}
SecretError::MissingEnvVar(var) => {
write!(f, "environment variable {var} referenced but not set")
}
}
}
}
impl Error for SecretError {}
/// Load a secret from the provided path /// Load a secret from the provided path
/// ///
/// If the provided path includes the `$CREDENTIALS_DIRECTORY` placeholder, it will be replaced with the /// If the provided path includes the `$CREDENTIALS_DIRECTORY` placeholder, it will be replaced with the