use thiserror::Error;
#[derive(Error, Debug)]
pub enum AuthError {
#[error("Authentication error: {0}")]
Authentication(String),
#[error("Configuration error: No eligible registry configuration found in .npmrc")]
NoNpmRegistry,
#[error("Authentication error: Failed to get credentials from ADC or gcloud")]
CredentialsUnavailable,
#[error(
"Configuration error: Bun environment credentials cannot be combined with local npm credentials"
)]
BunEnvLocalCredentialConflict,
#[error("Configuration error: Bun environment credentials require Bun support")]
BunEnvDisabledConflict,
#[error("IO error: {0}")]
Io(#[from] std::io::Error),
#[error("Configuration error: {0}")]
Config(String),
#[error("YAML parse error in {input}: {source}")]
YamlInput {
input: &'static str,
#[source]
source: yaml_edit::YamlError,
},
#[error("TOML parse error in bunfig.toml: {0}")]
TomlInput(#[from] toml_edit::TomlError),
#[error("Regex error: {0}")]
Regex(#[from] regex::Error),
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn library_errors_do_not_include_cli_guidance() {
for error in [
AuthError::NoNpmRegistry,
AuthError::CredentialsUnavailable,
AuthError::BunEnvLocalCredentialConflict,
AuthError::BunEnvDisabledConflict,
AuthError::Authentication("provider failed".to_string()),
] {
let message = error.to_string();
assert!(!message.contains('\n'));
assert!(!message.contains("--"));
assert!(!message.contains("Please run"));
assert!(!message.contains("Ensure"));
}
}
}