What is panicking here?

⚓ Rust    📅 2025-11-12    👤 surdeus    👁️ 4      

surdeus

Info

This post is auto-generated from RSS feed The Rust Programming Language Forum - Latest topics. Source: What is panicking here?

Consider:

fn read(
    settings: &DatabaseSettings,
    emailer: &Arc<dyn Emailer + Send + Sync + 'static>,
) -> Result<
    (
        HashMap<(SymbolType, Symbol), String>,
        HashMap<String, (String, String)>,
        HashMap<String, f64>,
    ),
    String,
> {
    let mut db_client = database::new_connection(&settings)?;
    let query = build_query();
    info!("SecurityCache Query: {}", query);
    let mut identifiers: HashMap<(SymbolType, Symbol), String> = HashMap::new();
    let mut currencies: HashMap<Symbol, (String, String)> = HashMap::new();
    let mut multipliers: HashMap<Symbol, f64> = HashMap::new();

    for row in db_client.query(&query, &[]).map_err(|e| e.to_string())? {
        let bbg: String = row.try_get(0).unwrap_or_default();
        let figi: String = row.try_get(1).unwrap_or_default();
        let multiplier: f64 = row.try_get(3).unwrap_or_default();
        let currency: String = row.try_get(4).unwrap_or_default();
        let quoted_currency: String = row.try_get(5).unwrap_or_default();

        identifiers.insert((SymbolType::FIGI, bbg.clone()), figi);
        currencies.insert(bbg.clone(), (currency, quoted_currency));
        multipliers.insert(bbg.clone(), multiplier);
    }

    if identifiers.len() == 0 {
        emailer.error(String::from("No identifiers found"));
    }

    Ok((identifiers, eze_symbols, currencies, multipliers))
}

If the query fails - in reality it was due to bad permissions - this fn panics.
I have been unable to figure out why.
This line:
for row in db_client.query(&query, &[]).map_err(|e| e.to_string())? {
should short-circuit with an Err.
Really confused by this one.

3 posts - 2 participants

Read full topic

🏷️ Rust_feed