replace production panics with graceful error handling in common crate

This commit is contained in:
Adil Hafeez 2026-03-25 04:19:07 +00:00
parent 406fa92802
commit 861fc382a4
3 changed files with 9 additions and 4 deletions

View file

@ -2,7 +2,6 @@ use crate::{
configuration::LlmProvider,
consts::{ARCH_FC_MODEL_NAME, ASSISTANT_ROLE},
};
use core::{panic, str};
use serde::{ser::SerializeMap, Deserialize, Serialize};
use std::{
collections::{HashMap, VecDeque},
@ -193,7 +192,7 @@ impl Display for ContentType {
// skip image URLs or their data in text representation
None
} else {
panic!("Unsupported content type: {:?}", part.content_type);
None
}
})
.collect();

View file

@ -75,7 +75,10 @@ pub trait Client: Context {
fn add_call_context(&self, id: u32, call_context: Self::CallContext) {
let callouts = self.callouts();
if callouts.borrow_mut().insert(id, call_context).is_some() {
panic!("Duplicate http call with id={}", id);
log::warn!(
"Duplicate http call with id={}, previous context overwritten",
id
);
}
self.active_http_calls().increment(1);
}

View file

@ -73,7 +73,10 @@ impl RatelimitMap {
match new_ratelimit_map.datastore.get_mut(&ratelimit_config.model) {
Some(limits) => match limits.get_mut(&ratelimit_config.selector) {
Some(_) => {
panic!("repeated selector. Selectors per provider must be unique")
log::error!(
"repeated selector for model '{}'. Selectors per provider must be unique, skipping duplicate",
ratelimit_config.model
);
}
None => {
limits.insert(ratelimit_config.selector, limit);