Skip to content

Fix #227: properly display SW360Error details on 4xx/5xx by checking response is not None - #243

Closed
dhruvv16-hash wants to merge 2 commits into
sw360:mainfrom
dhruvv16-hash:fix-issue-227
Closed

dhruvv16-hash wants to merge 2 commits into
sw360:mainfrom
dhruvv16-hash:fix-issue-227

Conversation

@dhruvv16-hash

Copy link
Copy Markdown

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.Response implements __bool__ such that it evaluates to False when status_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:.

Copilot AI lite review requested due to automatic review settings September 10, 2026 13:21

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 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: with if swex.response is not None: in project update error handling to ensure status/details are printed for 4xx/5xx responses.
  • Replaced if swex.response: with if 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.details handling is currently unreachable: after if swex.response is None: ... sys.exit(...), swex.response is guaranteed non-None, so if swex.response is not None: will always execute and exit before the subsequent if swex.details: block. This both leaves dead code and prevents swex.details from 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.

Comment thread capycli/bom/check_bom.py
Comment on lines +69 to 70
if swex.response is not None:
print(" Status Code: " + str(swex.response.status_code))
Comment thread capycli/project/create_project.py Outdated
Comment on lines 149 to 150
if swex.response is not None:
print_red(" " + str(swex.response.status_code) + ": " + swex.response.text)
@tngraf

tngraf commented Sep 10, 2026

Copy link
Copy Markdown
Collaborator
  1. Please provide units tests as suggested by Copilot.
  2. Run all checks (RunChecks.ps1).
  3. Consider fixing the bug everywhere and not just in one single file.

@gernot-h

Copy link
Copy Markdown
Collaborator

@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!

@dhruvv16-hash

Copy link
Copy Markdown
Author

Thanks for pointing that out @gernot-h! I completely missed PR #237 when looking for an issue to pick up. Closing this as a duplicate in favor of your fix. Apologies for the noise!

@gernot-h

Copy link
Copy Markdown
Collaborator

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!

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.

check_bom.py: Not reliable when printing SW360Error details

4 participants