Skip to content

Commit 76e3f46

Browse files
committed
Remove custom ProxyError and use anyhow directly
1 parent 5b9a760 commit 76e3f46

File tree

4 files changed

+8
-49
lines changed

4 files changed

+8
-49
lines changed

crates/llm/src/auth.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::config::DeploymentConfig;
2-
use crate::error::{ProxyError, Result};
2+
use anyhow::Result;
33
use base64::engine::{general_purpose, Engine};
44
use std::sync::Arc;
55
use std::time::{Duration, SystemTime};
@@ -70,10 +70,7 @@ impl TokenManager {
7070
let status = res.status();
7171
if !status.is_success() {
7272
let error_text = res.text().await?;
73-
return Err(ProxyError::Auth(format!(
74-
"Token request failed: {} - {}",
75-
status, error_text
76-
)));
73+
anyhow::bail!("Token request failed: {} - {}", status, error_text);
7774
}
7875

7976
let token_response = res.json::<TokenResponse>().await?;

crates/llm/src/config.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::error::{ProxyError, Result};
1+
use anyhow::{Context, Result};
22
use keyring::Entry;
33
use serde::{Deserialize, Serialize};
44

@@ -19,23 +19,23 @@ impl DeploymentConfig {
1919

2020
match keyring.get_password() {
2121
Ok(config_json) => serde_json::from_str(&config_json)
22-
.map_err(|e| ProxyError::Config(format!("Failed to parse config: {}", e))),
22+
.with_context(|| "Failed to parse config"),
2323
Err(keyring::Error::NoEntry) => {
2424
// If no config exists, create it interactively
2525
let config = Self::create_interactive()?;
2626
config.save()?;
2727
Ok(config)
2828
}
29-
Err(e) => Err(e.into()),
29+
Err(e) => Err(e).with_context(|| "Failed to access keyring"),
3030
}
3131
}
3232

3333
pub fn save(&self) -> Result<()> {
3434
let keyring = Entry::new(Self::SERVICE_NAME, Self::USERNAME)?;
3535
let config_json = serde_json::to_string(self)
36-
.map_err(|e| ProxyError::Config(format!("Failed to serialize config: {}", e)))?;
37-
keyring.set_password(&config_json)?;
38-
Ok(())
36+
.with_context(|| "Failed to serialize config")?;
37+
keyring.set_password(&config_json)
38+
.with_context(|| "Failed to save config to keyring")
3939
}
4040

4141
fn create_interactive() -> Result<Self> {

crates/llm/src/error.rs

Lines changed: 0 additions & 37 deletions
This file was deleted.

crates/llm/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ pub mod anthropic;
1919
pub mod anthropic_playback;
2020
pub mod auth;
2121
pub mod config;
22-
mod error;
2322
pub mod ollama;
2423
pub mod openai;
2524
pub mod openrouter;

0 commit comments

Comments
 (0)