You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
CLI: add th-cli doctor and never print an empty error (#1224) - #151
1. Never print an empty error when the backend request fails
Some httpx transport errors (ConnectError, ReadTimeout) have an empty str(), which produced Error: Unexpected error in list operation: Error handling response: with nothing after the colon, and the project wrapper dropped the exception type.
New describe_error() falls back to the exception class name and names the wrapped transport error. ResponseHandlingException and the commands' generic wrappers use it and chain the original exception.
Transport errors get the hint Is the backend running? Try th-cli doctor to diagnose.
th-cli --version now says why the versions could not be retrieved.
2. th-cli doctor
config: which config.json is used (or that the example file / defaults were) and the backend host. A broken config.json is reported here instead of exiting at import time; config.py skips its import-time exit when the first non-option argument is doctor.
backend reachable: GET /api/v1/version with a 5 s timeout, classified as connection refused / DNS / timeout / HTTP status.
versions: CLI version and SHA next to the backend version, SHA, SDK tag and db revision.
test runner and database (/projects/): warnings on failure.
Docker containers: skipped when docker is absent or with --no-docker; --log-lines N adds the backend log tail.
Exits non-zero on failure; --json for machine output.
Secrets are masked by key name and in free text, URL credentials are stripped, and IPs/MACs are masked unless --no-redact is given.
README documents the command.
Notes
The CLI and backend version schemes differ, so doctor shows the versions side by side but does not judge a mismatch.
Out of scope, as in the issue: a support-bundle command, a backend /health endpoint, TLS/auth.
Testing
New tests/test_doctor.py and tests/test_redaction.py, plus cases in test_exceptions.py and test_main.py. Coverage 87.6% (gate 85%).
Full suite: 47 failures, the same 47 that fail on v2.17-cli-develop without this branch (tc_params, validation, some run_tests).
Ran th-cli doctor on a Raspberry Pi 5 with a healthy Test Harness: all checks pass.
Some httpx transport errors (ConnectError, ReadTimeout) have an empty
str(), which produced messages like 'Error handling response:' with
nothing after the colon, and the project command wrapper dropped the
exception type altogether.
- Add describe_error(): falls back to the exception class name and
names the wrapped transport error.
- ResponseHandlingException and the commands' generic error wrappers
use it, and chain the original exception.
- Hint to check the backend (th-cli doctor) on transport errors.
- --version now says why the versions could not be retrieved.
Part of #1224
Checks, each reported as pass/warn/fail/skip:
- config: which config.json is used (or that defaults/example were),
and the resolved backend host. A bad config.json is reported here
instead of exiting at import time, which doctor is now exempt from.
- backend reachable: GET /api/v1/version with a short timeout, classified
as connection refused / DNS / timeout / HTTP status.
- versions: CLI version/sha next to the backend's version, sha, SDK tag
and db revision.
- test runner state and a DB-backed endpoint (/projects/), as warnings.
- Docker containers (skipped when docker is absent) and, with
--log-lines N, the backend log tail.
Exits non-zero on failure and supports --json. Secrets are masked by key
name and in free text, URL credentials are stripped, and IPs/MACs are
masked unless --no-redact is given.
Part of #1224
Auto reviews are disabled on base/target branches other than the default branch.
Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.
Run configuration
Source mode: Auto
Repository: Unavailable
Branch: Unavailable
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Organization UI
Review profile: CHILL
Plan: Advanced
Run ID: df18d875-a49f-4802-a573-5a4633a4a9a4
You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.
Use the checkbox below for a quick retry:
Trigger review
Walkthrough
The pull request adds and registers th-cli doctor. The command reports configuration, backend version and reachability, test-runner status, database access, and optional Docker checks. It supports text and JSON output, optional backend log tails, and default redaction of secrets and network addresses. The pull request also improves exception descriptions and backend hints in existing CLI error paths.
Sequence Diagram(s)
sequenceDiagram
participant User
participant doctor
participant run_checks
participant check_config
participant check_backend
participant BackendClient
participant check_docker
participant DockerCLI
User->>doctor: invoke command
doctor->>run_checks: request checks
run_checks->>check_config: load and classify configuration
run_checks->>check_backend: check configured backend
check_backend->>BackendClient: request version, runner, and projects probes
BackendClient-->>check_backend: return probe results
run_checks->>check_docker: inspect containers when enabled
check_docker->>DockerCLI: inspect containers and optional logs
DockerCLI-->>check_docker: return container state and log results
Loading
Possibly related PRs
project-chip/certification-tool-cli#143: Adds ConfigurationError for malformed config.json, which the doctor command catches to report the configuration error.
Suggested reviewers:oxesoft
Severity of issue fixed: Medium
Merge Risk: Moderate · previous review d53ca
The new doctor command can print the setup PIN or part of a password from backend logs in its report, and its JSON output can be corrupted by a startup warning when no config file exists. Fix the redaction and warning handling before merging; the missing doctor hints and the log-status handling are smaller follow-ups.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title names the two main changes: a new th-cli doctor command and a fix so that empty error messages are never printed. Both match the changeset (doctor.py, describe_error, unexpected_error, and…
Description check
The description explains both commits in detail: the empty-error fix with describe_error and the BACKEND_HINT, and the th-cli doctor command with its checks, options, redaction, and README update. It …
Linked Issues check
Issue #1224 is the only direct linked issue, and it is open. Its coding requirements are met according to the reviewed summary and PR description.
[Empty backend error text] describe_error() in `th…
Out of Scope Changes check
All changed files relate to the objectives of #1224 or to the documentation and tests for them.
- New th_cli/commands/doctor.py, th_cli/th_utils/redaction.py, and the doctor and redaction tests i…
Full details: Title check
Explanation
The title names the two main changes: a new th-cli doctor command and a fix so that empty error messages are never printed. Both match the changeset (doctor.py, describe_error, unexpected_error, and the README update). The title is specific and clearly describes the primary change.
Full details: Description check
Explanation
The description explains both commits in detail: the empty-error fix with describe_error and the BACKEND_HINT, and the th-cli doctor command with its checks, options, redaction, and README update. It also reports testing and coverage. It relates directly to the changeset.
Full details: Linked Issues check
Explanation
Issue #1224 is the only direct linked issue, and it is open. Its coding requirements are met according to the reviewed summary and PR description.
[Empty backend error text] describe_error() in th_cli/api_lib_autogen/exceptions.py falls back to the exception class name when str() is empty, and names the wrapped transport error. unexpected_error() in th_cli/exceptions.py keeps the exception type and appends BACKEND_HINT for ResponseHandlingException. Callers in project.py, available_tests.py, rescan_tests.py, run_tests.py, and test_run_execution.py use these helpers. tests/test_exceptions.py and tests/test_main.py cover the behavior.
[th-cli --version reason] th_cli/main.py now includes describe_error(e) when version retrieval fails. tests/test_main.py covers the unreachable-server case.
[Config reporting] check_config() in th_cli/commands/doctor.py reports the config source and resolved host. It catches ConfigurationError instead of exiting at import time. th_cli/config.py skips the import-time exit when the first non-option argument is doctor.
[Reachability] check_backend() calls GET /api/v1/version with a 5 s timeout. classify_error() distinguishes connection refused, DNS, timeout, and HTTP status.
[Versions] The CLI and backend version, SHA, SDK, and database revision values are reported side by side without a mismatch judgement, as the issue asks.
[Optional probes] The test runner state and /projects/ checks are present. Docker checks are skipped when Docker is absent or with --no-docker. --log-lines N adds the backend log tail.
[Output] Pass, warn, and fail results are reported. --json is supported and the command exits non-zero on failure.
[Redaction] th_cli/th_utils/redaction.py masks sensitive values by key name and in free text. It strips URL userinfo and masks IPs and MACs unless --no-redact is set. tests/test_redaction.py covers these cases.
[Tests] tests/test_doctor.py, tests/test_redaction.py, tests/test_exceptions.py, and tests/test_main.py are added or updated. The reported 87.6% coverage and the 47 pre-existing suite failures were not independently re-run.
The issue's non-coding items (manual Raspberry Pi test and screenshot) are not assessed. Out-of-scope items (support-bundle, backend /health, TLS/auth) are not required.
Full details: Out of Scope Changes check
Explanation
All changed files relate to the objectives of #1224 or to the documentation and tests for them.
New th_cli/commands/doctor.py, th_cli/th_utils/redaction.py, and the doctor and redaction tests implement the doctor command and its redaction.
th_cli/config.py changes support doctor by allowing it to run when config.json is invalid.
th_cli/exceptions.py, th_cli/api_lib_autogen/exceptions.py, and the command modules that use unexpected_error or describe_error replace empty or untyped error text. The issue requires this fix.
th_cli/main.py registers the command and reports the reason for version failures. th_cli/commands/__init__.py exports it.
README.md documents the command.
No change was found that is unrelated to the issue. The summary does not show any support-bundle, /health, or TLS/auth work.
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 5
Review info
Run configuration
Source mode: Auto
Repository: Unavailable
Branch: Unavailable
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Organization UI
Review profile: CHILL
Plan: Advanced
Run ID: b6051e7c-24e5-434e-88db-fd4114788eb6
Commits
Reviewing files that changed from the base of the PR and between dac2a6d and d53ca72.
Files selected for processing: 17
README.md
tests/test_doctor.py
tests/test_exceptions.py
tests/test_main.py
tests/test_redaction.py
th_cli/api_lib_autogen/exceptions.py
th_cli/commands/__init__.py
th_cli/commands/available_tests.py
th_cli/commands/doctor.py
th_cli/commands/project.py
th_cli/commands/rescan_tests.py
th_cli/commands/run_tests.py
th_cli/commands/test_run_execution.py
th_cli/config.py
th_cli/exceptions.py
th_cli/main.py
th_cli/th_utils/redaction.py
Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.
- Redaction: mask bare pin=<value> pairs and values containing escaped
quotes, which previously left part of a secret in the report.
- doctor --json: suppress the import-time 'Using default configuration'
warning for doctor, since check_config() reports it, so stdout stays
valid JSON.
- doctor: report a failed 'docker logs' as a warning instead of a pass.
- Add the th-cli doctor hint to the remaining transport-error paths
(available-tests, rescan-tests and the shared formatter used by repeat,
export and import); timeouts keep their own message.
Part of #1224
pytest-cov 4.x (used in CI) starts coverage inside child processes via
COV_CORE_* variables. The subprocess spawned by the import-time config
test then wrote coverage data from a temporary cwd, which corrupted the
parent report (omitted modules showed up at 0%, total 74.75%).
Part of #1224
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #1224
Two commits for one issue.
1. Never print an empty error when the backend request fails
ConnectError,ReadTimeout) have an emptystr(), which producedError: Unexpected error in list operation: Error handling response:with nothing after the colon, and theprojectwrapper dropped the exception type.describe_error()falls back to the exception class name and names the wrapped transport error.ResponseHandlingExceptionand the commands' generic wrappers use it and chain the original exception.Is the backend running? Try th-cli doctor to diagnose.th-cli --versionnow says why the versions could not be retrieved.2.
th-cli doctorconfig.jsonis used (or that the example file / defaults were) and the backend host. A brokenconfig.jsonis reported here instead of exiting at import time;config.pyskips its import-time exit when the first non-option argument isdoctor.GET /api/v1/versionwith a 5 s timeout, classified as connection refused / DNS / timeout / HTTP status./projects/): warnings on failure.dockeris absent or with--no-docker;--log-lines Nadds the backend log tail.--jsonfor machine output.--no-redactis given.Notes
doctorshows the versions side by side but does not judge a mismatch.support-bundlecommand, a backend/healthendpoint, TLS/auth.Testing
tests/test_doctor.pyandtests/test_redaction.py, plus cases intest_exceptions.pyandtest_main.py. Coverage 87.6% (gate 85%).v2.17-cli-developwithout this branch (tc_params,validation, somerun_tests).th-cli doctoron a Raspberry Pi 5 with a healthy Test Harness: all checks pass.