Skip to content

Commit e92b55a

Browse files
committed
fix(pricing): return flake lock field errors
Make LiteLLM flake.lock field extraction return InvalidData errors instead of reusing the CLI help helper that panics on missing or non-string fields. This keeps non-Nix Cargo builds on the locked LiteLLM revision while preserving build.rs error handling when flake.lock is malformed.
1 parent dd4bcf6 commit e92b55a

1 file changed

Lines changed: 19 additions & 3 deletions

File tree

‎rust/crates/ccusage/build.rs‎

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,15 +164,31 @@ fn litellm_pricing_url() -> std::io::Result<String> {
164164
"flake.lock is missing nodes.litellm.locked",
165165
)
166166
})?;
167-
let owner = string_field(locked, "owner");
168-
let repo = string_field(locked, "repo");
169-
let rev = string_field(locked, "rev");
167+
let owner = required_flake_lock_string_field(locked, "owner")?;
168+
let repo = required_flake_lock_string_field(locked, "repo")?;
169+
let rev = required_flake_lock_string_field(locked, "rev")?;
170170

171171
Ok(format!(
172172
"https://raw.githubusercontent.com/{owner}/{repo}/{rev}/{LITELLM_PRICING_JSON}"
173173
))
174174
}
175175

176+
fn required_flake_lock_string_field(
177+
object: &Map<String, Value>,
178+
field: &str,
179+
) -> std::io::Result<String> {
180+
object
181+
.get(field)
182+
.and_then(Value::as_str)
183+
.map(str::to_string)
184+
.ok_or_else(|| {
185+
std::io::Error::new(
186+
std::io::ErrorKind::InvalidData,
187+
format!("flake.lock nodes.litellm.locked.{field} must be a string"),
188+
)
189+
})
190+
}
191+
176192
fn compact_pricing_json(json: &str) -> Option<String> {
177193
let Value::Object(raw) = serde_json::from_str::<Value>(json).ok()? else {
178194
return None;

0 commit comments

Comments
 (0)