Skip to content

run_batch should return Err instead of calling process::exit(1) #67

Description

@ndenev

Summary

run_batch() calls std::process::exit(1) on query failure instead of returning an error, even though the function signature is Result<()>.

Affected code

  • src/main.rs (run_batch, error branch in query loop)

Why this is a problem

  1. Breaks function contract: run_batch is modeled as fallible (Result) but exits process directly.
  2. Skips normal drop/unwind path: process::exit bypasses standard Rust cleanup semantics.
  3. Prevents centralized error handling: caller (main) cannot intercept/format/classify batch errors consistently.
  4. Hurts composability/testability: impossible to reuse run_batch safely from other call sites.

Current behavior

Inside run_batch query loop:

  • on Err(e) from execute_sql_to_strings, it prints error and calls std::process::exit(1).

Proposed fix

  • Replace direct process exit with error propagation:
    • return Err(anyhow::anyhow!("Error executing query: {}", e));
  • Let top-level main own process exit policy.

Optional follow-up

  • Add a --keep-going mode for file-based multi-statement execution if desired.

Test coverage to add

  1. Batch file with one valid and one invalid statement:
    • verify non-zero process exit at top-level
    • verify error message
    • verify no hard exit inside run_batch
  2. Ensure error propagation path is exercised from main.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions