From d1a3eef80f4254f29ec1dbcc2d53a308b8a06e39 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Tue, 24 Feb 2026 13:14:45 +0000 Subject: [PATCH 1/3] Improve CLI error handling for invalid inputs Co-authored-by: EiJackGH <172181576+EiJackGH@users.noreply.github.com> --- .Jules/palette.md | 4 ++++ bitcoin_trading_simulation.py | 13 +++++++++++++ test_cli_args.py | 31 +++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+) create mode 100644 test_cli_args.py diff --git a/.Jules/palette.md b/.Jules/palette.md index 96bd45d..602d9ac 100644 --- a/.Jules/palette.md +++ b/.Jules/palette.md @@ -5,3 +5,7 @@ ## 2025-02-28 - Structured CLI Reports **Learning:** Dense numerical data in CLI output is hard to parse. Using ASCII box-drawing characters and alignment to create a "dashboard" or "invoice" style summary significantly improves readability and perceived quality. **Action:** When summarizing simulation or batch job results, always format the final report as a structured table or box rather than a list of print statements. + +## 2025-03-01 - Defensive CLI Design +**Learning:** Users often mistype arguments (e.g., negative numbers). Without validation, this leads to confusing output or crashes. Friendly error messages with actionable feedback are crucial for CLI usability. +**Action:** Always implement explicit validation for CLI arguments and provide colored, clear error messages before starting any heavy processing. diff --git a/bitcoin_trading_simulation.py b/bitcoin_trading_simulation.py index cb07d20..87d7e8a 100644 --- a/bitcoin_trading_simulation.py +++ b/bitcoin_trading_simulation.py @@ -142,6 +142,19 @@ def countdown(quiet=False): if args.no_color: Colors.disable() + if args.days <= 0: + print(f"{Colors.FAIL}Error: --days must be a positive integer.{Colors.ENDC}") + sys.exit(1) + if args.initial_cash <= 0: + print(f"{Colors.FAIL}Error: --initial-cash must be a positive amount.{Colors.ENDC}") + sys.exit(1) + if args.initial_price <= 0: + print(f"{Colors.FAIL}Error: --initial-price must be a positive amount.{Colors.ENDC}") + sys.exit(1) + if args.volatility < 0: + print(f"{Colors.FAIL}Error: --volatility must be non-negative.{Colors.ENDC}") + sys.exit(1) + # Simulate prices prices = simulate_bitcoin_prices(days=args.days, initial_price=args.initial_price, volatility=args.volatility) diff --git a/test_cli_args.py b/test_cli_args.py new file mode 100644 index 0000000..1fdc64d --- /dev/null +++ b/test_cli_args.py @@ -0,0 +1,31 @@ +import subprocess +import sys + + +def run_cli(args): + return subprocess.run( + [sys.executable, "bitcoin_trading_simulation.py"] + args, + capture_output=True, + text=True + ) + + +def test_negative_days_error(): + """Negative days should fail with a helpful error message.""" + result = run_cli(["--days", "-5", "--quiet"]) + assert result.returncode == 1 + assert "Error: --days must be a positive integer" in result.stdout + + +def test_negative_cash_error(): + """Negative cash should fail with a helpful error message.""" + result = run_cli(["--initial-cash", "-100", "--quiet"]) + assert result.returncode == 1 + assert "Error: --initial-cash must be a positive amount" in result.stdout + + +def test_negative_volatility_error(): + """Negative volatility should fail with a helpful error message.""" + result = run_cli(["--volatility", "-0.1", "--quiet"]) + assert result.returncode == 1 + assert "Error: --volatility must be non-negative" in result.stdout From 40e5bf2a04a1dbb57f76a170835be68b8733a12d Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Tue, 24 Feb 2026 13:18:44 +0000 Subject: [PATCH 2/3] Improve CLI error handling and remove invalid Rust CI workflow Co-authored-by: EiJackGH <172181576+EiJackGH@users.noreply.github.com> --- .github/workflows/rust.yml | 22 ---------------------- 1 file changed, 22 deletions(-) delete mode 100644 .github/workflows/rust.yml diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml deleted file mode 100644 index 9fd45e0..0000000 --- a/.github/workflows/rust.yml +++ /dev/null @@ -1,22 +0,0 @@ -name: Rust - -on: - push: - branches: [ "main" ] - pull_request: - branches: [ "main" ] - -env: - CARGO_TERM_COLOR: always - -jobs: - build: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - - name: Build - run: cargo build --verbose - - name: Run tests - run: cargo test --verbose From 5a54b6235aff13285e56d11e1e0ca63fbe921bb3 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Fri, 27 Feb 2026 11:22:55 +0000 Subject: [PATCH 3/3] Improve CLI error handling and modernize CI workflows Co-authored-by: EiJackGH <172181576+EiJackGH@users.noreply.github.com> --- .github/workflows/python-package.yml | 2 +- .github/workflows/stale.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index dc172e0..6959259 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -21,7 +21,7 @@ jobs: steps: - uses: actions/checkout@v4 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v3 + uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} - name: Install dependencies diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml index 10e636f..ca645aa 100644 --- a/.github/workflows/stale.yml +++ b/.github/workflows/stale.yml @@ -18,7 +18,7 @@ jobs: pull-requests: write steps: - - uses: actions/stale@v5 + - uses: actions/stale@v9 with: repo-token: ${{ secrets.GITHUB_TOKEN }} stale-issue-message: 'Stale issue message'