Skip to content

fix(cli): raise on explicit --profile resolution failure instead of silent localhost fallback#414

Open
Chaffelson wants to merge 1 commit into
mainfrom
fix/cli-explicit-profile-loud-error
Open

fix(cli): raise on explicit --profile resolution failure instead of silent localhost fallback#414
Chaffelson wants to merge 1 commit into
mainfrom
fix/cli-explicit-profile-loud-error

Conversation

@Chaffelson

Copy link
Copy Markdown
Owner

Summary

An explicit --profile whose resolution failed was swallowed by a bare except ValueError: pass in the CLI entry point, leaving the SDK on its default localhost:9443 endpoint. Users then hit a confusing localhost connection error on the first API call instead of the real cause — a missing or misconfigured profile.

This extracts profile application into a small _apply_profile() helper:

  • Explicit --profile that fails to resolve now emits a structured error naming the profile and exits non-zero.
  • Auto-resolution (no --profile given) still falls through, so configuration errors surface on the first API call — preserving the just-works-without-config behaviour.

Test plan

  • make lint — 10.00/10
  • make test NIPYAPI_PROFILE=single-user PYTEST_ARGS="-v tests/test_cli.py" — 96 passed (adds 3 unit tests: explicit-failure, auto-resolve, success paths)

…ilent localhost fallback

An explicit `--profile` whose resolution failed was swallowed by a bare
`except ValueError: pass`, leaving the SDK on its default localhost endpoint.
The user then hit a confusing localhost connection error on the first API
call instead of the real cause (missing/misconfigured profile).

Extract profile application into `_apply_profile()`: an explicit `--profile`
failure now emits a structured error and exits non-zero, while auto-resolution
(no `--profile` given) still falls through so configuration errors surface on
the first API call, preserving the just-works-without-config behaviour. Adds
unit tests for the explicit-failure, auto-resolve, and success paths.
@codecov

codecov Bot commented Jul 20, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.66667% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 77.22%. Comparing base (759aae8) to head (0eb68f7).

Files with missing lines Patch % Lines
nipyapi/cli.py 91.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #414      +/-   ##
==========================================
+ Coverage   77.12%   77.22%   +0.09%     
==========================================
  Files          41       41              
  Lines        4954     4962       +8     
==========================================
+ Hits         3821     3832      +11     
+ Misses       1133     1130       -3     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread nipyapi/cli.py

try:
nipyapi.profiles.switch(explicit_profile)
except ValueError as e:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why check for none after making a call? Would it be better to move this check outside the try block?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants