1use thiserror::Error;
4
5#[derive(Error, Debug)]
7pub enum AuthError {
8 #[error("Authentication error: {0}")]
10 Authentication(String),
11
12 #[error("Configuration error: No eligible registry configuration found in .npmrc")]
14 NoNpmRegistry,
15
16 #[error("Authentication error: Failed to get credentials from ADC or gcloud")]
18 CredentialsUnavailable,
19
20 #[error(
22 "Configuration error: Bun environment credentials cannot be combined with local npm credentials"
23 )]
24 BunEnvLocalCredentialConflict,
25
26 #[error("Configuration error: Bun environment credentials require Bun support")]
28 BunEnvDisabledConflict,
29
30 #[error("IO error: {0}")]
32 Io(#[from] std::io::Error),
33
34 #[error("Configuration error: {0}")]
36 Config(String),
37
38 #[error("YAML parse error in {input}: {source}")]
40 YamlInput {
41 input: &'static str,
43 #[source]
45 source: yaml_edit::YamlError,
46 },
47
48 #[error("TOML parse error in bunfig.toml: {0}")]
50 TomlInput(#[from] toml_edit::TomlError),
51
52 #[error("Regex error: {0}")]
54 Regex(#[from] regex::Error),
55}
56
57#[cfg(test)]
58mod tests {
59 use super::*;
60
61 #[test]
62 fn library_errors_do_not_include_cli_guidance() {
63 for error in [
64 AuthError::NoNpmRegistry,
65 AuthError::CredentialsUnavailable,
66 AuthError::BunEnvLocalCredentialConflict,
67 AuthError::BunEnvDisabledConflict,
68 AuthError::Authentication("provider failed".to_string()),
69 ] {
70 let message = error.to_string();
71 assert!(!message.contains('\n'));
72 assert!(!message.contains("--"));
73 assert!(!message.contains("Please run"));
74 assert!(!message.contains("Ensure"));
75 }
76 }
77}