Bug Description
When using --output-format with an invalid value (including case-sensitive mismatches like TEXT instead of text), the CLI crashes with a raw Python traceback instead of displaying a user-friendly error message.
Steps to Reproduce
- Run
iac-code -p "hello" --output-format invalid
- Or run
iac-code -p "hello" --output-format TEXT
Expected Behavior
A clean error message like:
Error: Invalid output format 'invalid'. Valid formats: text, json, stream-json
Actual Behavior
A full Python traceback is displayed:
Traceback (most recent call last):
File ".../bin/iac-code", line 6, in <module>
sys.exit(app())
...
File ".../iac_code/cli/main.py", line 191, in main
fmt = OutputFormat(output_format)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".../enum.py", line 1171, in __new__
raise ve_exc
ValueError: 'invalid' is not a valid OutputFormat
Root Cause
In src/iac_code/cli/main.py line 191, OutputFormat(output_format) is called without a try/except:
fmt = OutputFormat(output_format)
A fix would be to catch the ValueError and print a friendly message:
try:
fmt = OutputFormat(output_format)
except ValueError:
valid = ", ".join(f.value for f in OutputFormat)
typer.echo(f"Invalid output format '{output_format}'. Valid formats: {valid}", err=True)
raise typer.Exit(1)
Operating System
macOS
Python Version
3.12.7
iac-code Version
0.2.3
LLM Provider
Alibaba Cloud (DashScope / Qwen)
IaC Type
Not applicable
Additional Context
This also affects case-sensitive inputs — a user typing --output-format JSON gets a crash instead of a helpful hint. Consider normalizing the input with .lower() before validation.
Bug Description
When using
--output-formatwith an invalid value (including case-sensitive mismatches likeTEXTinstead oftext), the CLI crashes with a raw Python traceback instead of displaying a user-friendly error message.Steps to Reproduce
iac-code -p "hello" --output-format invalidiac-code -p "hello" --output-format TEXTExpected Behavior
A clean error message like:
Actual Behavior
A full Python traceback is displayed:
Root Cause
In
src/iac_code/cli/main.pyline 191,OutputFormat(output_format)is called without a try/except:A fix would be to catch the
ValueErrorand print a friendly message:Operating System
macOS
Python Version
3.12.7
iac-code Version
0.2.3
LLM Provider
Alibaba Cloud (DashScope / Qwen)
IaC Type
Not applicable
Additional Context
This also affects case-sensitive inputs — a user typing
--output-format JSONgets a crash instead of a helpful hint. Consider normalizing the input with.lower()before validation.