Skip to content

Commit 34103f9

Browse files
committed
improving error handeling in cli
1 parent afdd483 commit 34103f9

1 file changed

Lines changed: 18 additions & 5 deletions

File tree

devolv/iam/validator/cli.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,30 @@
11
import typer
22
from devolv.iam.validator.core import validate_policy_file
33

4-
app = typer.Typer(help="IAM Validator CLI")
4+
file_app = typer.Typer(help="Commands to validate IAM policy files.")
55

6-
@app.command("file")
6+
@file_app.command("file")
77
def validate_file(path: str):
88
"""
99
Validate an AWS IAM policy file (JSON or YAML).
1010
"""
11-
findings = validate_policy_file(path)
11+
try:
12+
findings = validate_policy_file(path)
13+
except FileNotFoundError:
14+
typer.secho(f"❌ File not found: {path}", fg=typer.colors.RED)
15+
raise typer.Exit(code=1)
16+
except ValueError as e:
17+
typer.secho(f"❌ Error: {e}", fg=typer.colors.RED)
18+
raise typer.Exit(code=1)
19+
except Exception as e:
20+
typer.secho(f"❌ Unexpected error: {e}", fg=typer.colors.RED)
21+
raise typer.Exit(code=1)
22+
1223
if not findings:
1324
typer.secho("✅ Policy is valid and passed all checks.", fg=typer.colors.GREEN)
1425
else:
26+
typer.secho("⚠️ Issues found in the policy:", fg=typer.colors.YELLOW)
1527
for finding in findings:
16-
typer.secho(f"❌ {finding['level'].upper()}: {finding['message']}", fg=typer.colors.RED)
17-
raise typer.Exit(code=1)
28+
typer.secho(f" - {finding['level'].upper()}: {finding['message']}", fg=typer.colors.RED)
29+
raise typer.Exit(code=2)
30+

0 commit comments

Comments
 (0)