louis-e/arnis · error

provider chain is never empty

Error message

provider chain is never empty

What it means

`fetch_raw_with_fallback` iterates a chain of elevation data providers and, if the loop ends without returning, hits `unreachable!("provider chain is never empty")`. The invariant assumes the provider chain is constructed with at least one provider, so the only way to reach this line is an empty chain.

Solutions

  1. Ensure at least one elevation provider is configured/enabled before calling `fetch_elevation_data`
  2. Validate the provider chain is non-empty early and return a proper `Err(String)` like "no elevation providers configured" instead of relying on unreachable!
  3. Enable the default provider feature or add a fallback provider to the chain construction

Example fix

// before
unreachable!("provider chain is never empty")
// after
Err(anyhow!("no elevation providers configured"))
Defensive patterns

Strategy: validation

Validate before calling

if providers.is_empty() { return Err(anyhow!("no elevation providers configured; enable at least one source")); }

Type guard

fn has_provider(chain: &[Box<dyn ElevationProvider>]) -> bool { !chain.is_empty() }

Prevention

When it happens

Trigger: Building the provider list with configuration that selects zero providers (e.g. all elevation sources disabled, an empty/invalid config, or a feature-gated build where every provider is compiled out) and then calling `fetch_elevation_data`.

Common situations: Config file with all elevation providers turned off; CLI flags excluding every source; a build without the default provider features enabled.

Related errors


AI-assisted analysis of louis-e/arnis@34048924d9 (2026-09-03). Data as JSON: /api/errors/91f709a54f2004c7. Report an issue: GitHub.

Appendix: source

Thrown at src/elevation/mod.rs:325

                    name,
                    e,
                    chain[i + 1].name()
                );
                #[cfg(feature = "gui")]
                crate::telemetry::send_log(
                    crate::telemetry::LogLevel::Warning,
                    &format!(
                        "Elevation provider '{}' failed, falling back to '{}'.",
                        name,
                        chain[i + 1].name()
                    ),
                );
                emit_gui_progress_update(10.0, "Downloading data...");
            }
            Err(e) => return Err(e),
        }
    }
    unreachable!("provider chain is never empty")
}

/// Compute the fraction of NaN/non-finite values in a height grid (0.0 to 1.0).
fn compute_nan_ratio(heights: &[Vec<f64>]) -> f64 {
    let mut total = 0usize;
    let mut nan_count = 0usize;
    for row in heights {
        for &h in row {
            total += 1;
            if !h.is_finite() {
                nan_count += 1;
            }
        }
    }
    if total == 0 {
        return 1.0;
    }
    nan_count as f64 / total as f64

View on GitHub (pinned to 34048924d9)