Fix #227: properly display SW360Error details on 4xx/5xx by checking response is not None - #243
dhruvv16-hash wants to merge 2 commits into
Conversation
…king response is not None
There was a problem hiding this comment.
🟡 Changes recommended
In create_project.py, the new swex.response is not None branch makes the subsequent swex.details handling unreachable, preventing details from ever being shown when present.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR addresses #227 by ensuring SW360Error response information is shown even for HTTP error responses, avoiding requests.Response falsey behavior (status_code >= 400) by switching from truthiness checks to explicit is not None checks.
Changes:
- Replaced
if swex.response:withif swex.response is not None:in project update error handling to ensure status/details are printed for 4xx/5xx responses. - Replaced
if swex.response:withif swex.response is not None:in BOM checking error logging to consistently print the HTTP status code for error responses.
File summaries
| File | Description |
|---|---|
| capycli/project/create_project.py | Updates SW360Error response presence check to avoid Response.__bool__ falsey behavior for 4xx/5xx. |
| capycli/bom/check_bom.py | Ensures SW360Error status code logging triggers for error responses by checking response against None. |
Review details
Suppressed comments (1)
capycli/project/create_project.py:153
swex.detailshandling is currently unreachable: afterif swex.response is None: ... sys.exit(...),swex.responseis guaranteed non-None, soif swex.response is not None:will always execute and exit before the subsequentif swex.details:block. This both leaves dead code and preventsswex.detailsfrom ever being displayed when present.
if swex.response is not None:
print_red(" " + str(swex.response.status_code) + ": " + swex.response.text)
sys.exit(ResultCode.RESULT_ERROR_ACCESSING_SW360)
if swex.details:
print_red(" " + swex.details.get("error", "") + ": " + swex.details.get("message", ""))
- Files reviewed: 2/2 changed files
- Comments generated: 2
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| if swex.response is not None: | ||
| print(" Status Code: " + str(swex.response.status_code)) |
| if swex.response is not None: | ||
| print_red(" " + str(swex.response.status_code) + ": " + swex.response.text) |
|
|
@dhruvv16-hash, thanks for looking into this! However, did you notice that I already worked on #227 and created #237 to address it which is currently under review? So please check #237 and join our discussion there first. If you think that my approach is wrong and we should go another way, that's fine, but it would be good if you would let us know why you decided to go for a fresh approach, thanks in advance! |
|
Not at all! I'd be happy if you could join the review of my suggestion, feel free to compare it to yours and let us know in #237 if you have a better approach! |
Fixes #227
Description
This PR fixes an issue where SW360Error details were being silently swallowed for 4xx and 5xx HTTP responses.
The bug occurred because
requests.Responseimplements__bool__such that it evaluates toFalsewhenstatus_code >= 400. Thus,if swex.response:was inadvertently skipping the error detail logging whenever a true HTTP error occurred, logging nothing instead.This has been resolved globally by explicitly checking
if swex.response is not None:.