Skip to content

Show fail message when manifest is found but go is not installed#308

Merged
dd-jy merged 1 commit intomainfrom
go_test
Apr 15, 2026
Merged

Show fail message when manifest is found but go is not installed#308
dd-jy merged 1 commit intomainfrom
go_test

Conversation

@woocheol-lge
Copy link
Copy Markdown
Contributor

@woocheol-lge woocheol-lge commented Apr 14, 2026

Description

Show fail message when manifest is found but go is not installed

Summary by CodeRabbit

  • Bug Fixes
    • Better handling when the Go toolchain is missing: scans abort cleanly and report failure.
    • Ensures temporary workspace state is always restored after a scan, even on errors.
    • Stops processing on failed dependency list commands and only parses dependency graph output when present, reducing false errors.

@woocheol-lge woocheol-lge requested a review from dd-jy April 14, 2026 01:41
@woocheol-lge woocheol-lge self-assigned this Apr 14, 2026
@woocheol-lge woocheol-lge added the chore [PR/Issue] Refactoring, maintenance the code label Apr 14, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 14, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 86401225-7744-41cf-b18c-9909f26baccd

📥 Commits

Reviewing files that changed from the base of the PR and between 1a5b5c9 and 413d289.

📒 Files selected for processing (1)
  • src/fosslight_dependency/package_manager/Go.py

📝 Walkthrough

Walkthrough

run_plugin() in the Go package manager now resolves the go executable with shutil.which, aborts early if missing, wraps execution in a try/finally to reliably restore a moved go.work, returns early on non-zero go list exit, and only parses go mod graph output when non-empty while preventing its exceptions from escaping.

Changes

Cohort / File(s) Summary
Go plugin runtime & cleanup
src/fosslight_dependency/package_manager/Go.py
Resolve go via shutil.which and abort if absent; run plugin inside try/finally and track/move back go.work.tmp -> go.work on exit; return False immediately on non-zero go list exit; parse go mod graph only when output is non-empty and prevent its exceptions from propagating.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main behavioral change: detecting when a Go manifest exists but the go executable is not installed and showing a fail message.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch go_test

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/fosslight_dependency/package_manager/Go.py`:
- Around line 74-79: In run_plugin(), the block that captures `ret_cmd_tree =
subprocess.check_output(cmd_tree, shell=True, text=True, encoding='utf-8')`
incorrectly checks `if ret_cmd_tree != 0:` and swallows subprocess failures;
change the condition to check for a non-empty string (e.g., `if ret_cmd_tree:`)
and call `self.parse_dependency_tree(ret_cmd_tree)` only then, and additionally
catch subprocess.CalledProcessError (or set `ret = False` in the except block)
so that when `subprocess.check_output` fails the method records failure instead
of leaving `ret` unchanged; update the exception logging in run_plugin() to
include the exception details and ensure `ret` is set to False when
parse/command execution fails so callers see the correct failure state.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: dd74e3eb-2f99-42a7-a753-e55bf0fade22

📥 Commits

Reviewing files that changed from the base of the PR and between 203acab and 1a5b5c9.

📒 Files selected for processing (1)
  • src/fosslight_dependency/package_manager/Go.py

Comment on lines +74 to +79
try:
ret_cmd_tree = subprocess.check_output(cmd_tree, shell=True, text=True, encoding='utf-8')
if ret_cmd_tree != 0:
self.parse_dependency_tree(ret_cmd_tree)
except Exception as e:
logger.warning(f"Failed to run '{cmd_tree}': {e}")
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🌐 Web query:

According to Python documentation, what does subprocess.check_output return when text=True, and what exception is raised when the command exits with a non-zero status?

💡 Result:

According to the Python documentation, subprocess.check_output with text=True returns the stdout of the executed command as a string if the command exits with a zero status. If the command exits with a non-zero status, it raises subprocess.CalledProcessError.

Citations:


Fix go mod graph failure handling in run_plugin().

At line 76, ret_cmd_tree is a string returned by subprocess.check_output(..., text=True), so the condition if ret_cmd_tree != 0: is incorrect and should check for a non-empty string instead.

At line 79, when an exception occurs, the code only logs a warning and leaves ret unchanged. Since subprocess.check_output() raises CalledProcessError on non-zero exit, the failure is silently ignored and the function still returns success.

Proposed fix
         cmd_tree = "go mod graph"
         try:
             ret_cmd_tree = subprocess.check_output(cmd_tree, shell=True, text=True, encoding='utf-8')
-            if ret_cmd_tree != 0:
+            if ret_cmd_tree:
                 self.parse_dependency_tree(ret_cmd_tree)
-        except Exception as e:
+        except subprocess.CalledProcessError as e:
+            logger.error(f"Failed to run '{cmd_tree}': {e}")
+            ret = False
+        except Exception as e:
             logger.error(f"Failed to run '{cmd_tree}': {e}")
+            ret = False
🧰 Tools
🪛 Ruff (0.15.9)

[error] 75-75: subprocess call with shell=True identified, security issue

(S602)


[warning] 78-78: Do not catch blind exception: Exception

(BLE001)

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/fosslight_dependency/package_manager/Go.py` around lines 74 - 79, In
run_plugin(), the block that captures `ret_cmd_tree =
subprocess.check_output(cmd_tree, shell=True, text=True, encoding='utf-8')`
incorrectly checks `if ret_cmd_tree != 0:` and swallows subprocess failures;
change the condition to check for a non-empty string (e.g., `if ret_cmd_tree:`)
and call `self.parse_dependency_tree(ret_cmd_tree)` only then, and additionally
catch subprocess.CalledProcessError (or set `ret = False` in the except block)
so that when `subprocess.check_output` fails the method records failure instead
of leaving `ret` unchanged; update the exception logging in run_plugin() to
include the exception details and ensure `ret` is set to False when
parse/command execution fails so callers see the correct failure state.

Comment thread src/fosslight_dependency/package_manager/Go.py
Comment thread src/fosslight_dependency/package_manager/Go.py Outdated
…talled

Signed-off-by: woocheol <jayden6659@gmail.com>
@dd-jy dd-jy merged commit 1e032e0 into main Apr 15, 2026
15 checks passed
@dd-jy dd-jy deleted the go_test branch April 15, 2026 06:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

chore [PR/Issue] Refactoring, maintenance the code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants