Skip to content

databend-query panics with unfriendly error when config file does not exist #19961

@wubx

Description

@wubx

Summary

When starting databend-query with -c pointing to a config file that does not exist, the process panics with a confusing unwrap() backtrace instead of printing a clear "config file not found" message.

Steps to reproduce

./databend-query -c /etc/databend/databend-query-3308.toml
# where /etc/databend/databend-query-3308.toml does NOT exist

Output:

thread 'main' (5227) panicked at src/binaries/query/cmd.rs:58:49:
called `Result::unwrap()` on an `Err` value: anyhow. Code: 1002, Text = No such file or directory (os error 2), source: None
No such file or directory (os error 2).

<Backtrace disabled by default. Please use RUST_BACKTRACE=1 to enable>
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Databend Query start failure, cause: UnwindError. Code: 1104, Text = called `Result::unwrap()` on an `Err` value: anyhow. Code: 1002, Text = No such file or directory (os error 2), source: None
No such file or directory (os error 2).

Confirming the file really is missing:

$ ls /etc/databend/databend-query-3308.toml
ls: cannot access '/etc/databend/databend-query-3308.toml': No such file or directory

Root cause

In src/binaries/query/cmd.rs (around line 58):

let config = config.merge(&config_file).unwrap();

init_inner_config already returns Result<InnerConfig>, but merge() is unwrap()-ed, so a missing file is turned into a panic instead of a normal error return. Two problems:

  1. A simple "file not found" should not produce a panic / backtrace.
  2. The message does not include the offending file path, so the user cannot tell which config file is missing from the message alone.

Expected behavior

  • No panic / no backtrace for a missing config file.

  • A clear, single-line error that includes the path, for example:

    failed to load config file "/etc/databend/databend-query-3308.toml": No such file or directory (os error 2)
    

Suggested fix

Propagate the error with context instead of unwrapping, e.g.:

use anyhow::Context;

let config = config
    .merge(&config_file)
    .with_context(|| format!("failed to load config file {config_file:?}"))?;

Environment

  • This affects the current release as well (not specific to one version).
  • Component: databend-query
  • Source: src/binaries/query/cmd.rs

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions