mirror of
https://codeberg.org/icewind/secretfile.git
synced 2026-06-03 16:44:08 +02:00
drop thiserror
This commit is contained in:
parent
a85d150038
commit
c7439f746d
3 changed files with 19 additions and 66 deletions
22
src/lib.rs
22
src/lib.rs
|
|
@ -1,16 +1,30 @@
|
|||
use std::borrow::Cow;
|
||||
use std::env::var;
|
||||
use std::error::Error;
|
||||
use std::fmt::Display;
|
||||
use std::fs::read_to_string;
|
||||
use thiserror::Error;
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
#[derive(Debug)]
|
||||
pub enum SecretError {
|
||||
#[error("failed to load token from {path}: {error:#}")]
|
||||
Load { path: String, error: std::io::Error },
|
||||
#[error("environment variable {0} referenced but not set")]
|
||||
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
|
||||
///
|
||||
/// If the provided path includes the `$CREDENTIALS_DIRECTORY` placeholder, it will be replaced with the
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue