CLI errors
Common error signatures
Errors in the CLI fall into two categories: argument parsing failures raised before any retrieval logic runs, and runtime failures returned as non-zero exit codes from main().
- Unrecognized or missing arguments —
argparseprints a usage message and exits with code2when you pass an unknown flag or omit a required positional argument. - Invalid subcommand — calling
attune-ragwithout a subcommand (queryorcorpus-info) produces an argument error and exits before any retrieval work begins. - Runtime failure in
main()— exceptions caught insidemain()are reflected in the integer return value; a non-zero return indicates the command did not complete successfully.
Where errors originate
Both functions in src/attune_rag/cli.py are potential failure sites:
build_parser()— constructs theArgumentParser. Errors here are typicallySystemExitraised byargparsein response to bad input. They occur before retrieval starts.main(argv)— drives the full command lifecycle. Failures here can originate from downstream retrieval or corpus logic and are surfaced as the integer return value of the function.
How to diagnose
-
Check the exit code. A code of
2points to an argument parsing error inbuild_parser(). Any other non-zero code points to a failure insidemain(). -
Read the
argparseerror message. When argument parsing fails,argparseprints the specific problem — missing argument, unrecognized flag, or invalid value — directly tostderrbefore exiting. -
Pass
argvexplicitly during debugging. Becausemain()accepts an optionalargv: list[str]parameter, you can call it directly in a Python session with a known-good argument list to isolate whether the failure is in argument parsing or in retrieval logic. -
Capture the full traceback for unexpected exceptions. If
main()raises rather than returning a non-zero integer, the traceback will name the exact file and line. Errors originating outsidecli.pyitself indicate the CLI is propagating a failure from the retrieval layer.
Source files
src/attune_rag/cli.py
Tags: cli, query, corpus-info