Skip to content

fix(pkg/app/eventwatcher): log temporary repository cleanup errors - #7325

Open
anubhavsingh2106 wants to merge 1 commit into
pipe-cd:masterfrom
anubhavsingh2106:fix/eventwatcher-log-clean-errors
Open

fix(pkg/app/eventwatcher): log temporary repository cleanup errors#7325
anubhavsingh2106 wants to merge 1 commit into
pipe-cd:masterfrom
anubhavsingh2106:fix/eventwatcher-log-clean-errors

Conversation

@anubhavsingh2106

@anubhavsingh2106 anubhavsingh2106 commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Handle errors returned by tmpRepo.Clean() instead of suppressing them with nolint: errcheck.
  • Log cleanup failures with the temporary repository path for easier diagnosis.
  • Remove the parent temporary directory (tmpDir) after successful repository cleanup to prevent empty temporary directories from accumulating during the watcher's lifetime.
  • Log failures when removing the parent temporary directory.
  • Apply the same cleanup handling to both eventwatcher implementations.

Files Changed

  • pkg/app/piped/eventwatcher/eventwatcher.go
  • pkg/app/pipedv1/eventwatcher/eventwatcher.go

Testing

  • go test ./pkg/app/piped/eventwatcher ./pkg/app/pipedv1/eventwatcher — passed.
  • git diff --check — passed.
  • gofmt — applied with no unrelated formatting changes.

Note

The eventwatcher tests initially failed on Windows because the testdata files had CRLF line endings while TestModifyText compares the generated content against LF-based expected content. The files were temporarily normalized locally for test execution and restored afterward; no test or testdata changes are included in this PR.

Copilot AI lite review requested due to automatic review settings September 6, 2026 19:22
@anubhavsingh2106
anubhavsingh2106 requested review from a team as code owners September 6, 2026 19:22
@netlify

netlify Bot commented Sep 6, 2026

Copy link
Copy Markdown

Deploy Preview for pipecd-site canceled.

Name Link
🔨 Latest commit 6f24b68
🔍 Latest deploy log https://app.netlify.com/projects/pipecd-site/deploys/6a9efac3b2e1be000850f682

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The change is small, consistent across both implementations, and correctly adds error-aware cleanup logging without altering core eventwatcher behavior.

Pull request overview

This PR improves the reliability and debuggability of PipeCD’s eventwatcher temporary-repository lifecycle by no longer suppressing cleanup errors and by logging cleanup failures with the affected repository path (in both legacy piped and pipedv1 implementations).

Changes:

  • Replaced // nolint: errcheck + defer tmpRepo.Clean() with a deferred cleanup function that checks and logs tmpRepo.Clean() errors.
  • Included the temporary repository path in the error log fields to aid diagnosis.
  • Applied the same cleanup-error logging pattern to both eventwatcher implementations.
File summaries
File Description
pkg/app/piped/eventwatcher/eventwatcher.go Logs temporary repo cleanup failures instead of suppressing cleanup errors.
pkg/app/pipedv1/eventwatcher/eventwatcher.go Mirrors the same deferred cleanup error handling/logging in the pipedv1 eventwatcher.
Review details
  • 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 pkg/app/piped/eventwatcher/eventwatcher.go
Comment thread pkg/app/pipedv1/eventwatcher/eventwatcher.go

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The current cleanup logic can still leak temporary directories on CopyToModify failures and uses os.Remove (which can fail for non-empty dirs), so the cleanup behavior should be tightened before approval.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 2
  • Review effort level: Lite

Comment thread pkg/app/piped/eventwatcher/eventwatcher.go Outdated
Comment thread pkg/app/pipedv1/eventwatcher/eventwatcher.go Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The updated cleanup logic no longer calls tmpRepo.Clean(), so it doesn’t actually handle/log tmpRepo.Clean() errors as stated in the PR description and may bypass repo-specific cleanup semantics.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 2
  • Review effort level: Lite

Comment thread pkg/app/piped/eventwatcher/eventwatcher.go
Comment thread pkg/app/pipedv1/eventwatcher/eventwatcher.go
Signed-off-by: Anubhav Singh <anmolkfzd@gmail.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Cleanup behavior and PR description are inconsistent (tmpDir removal occurs even when repo cleanup fails), and the still-invoked updateValues() path retains the old error-suppressing/leaky cleanup behavior.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details

Suppressed comments (2)

pkg/app/pipedv1/eventwatcher/eventwatcher.go:335

  • The deferred cleanup always calls os.RemoveAll(tmpDir) even when tmpRepo.Clean() fails. This contradicts the PR description (“remove tmpDir after successful repository cleanup”) and can delete the leftover repo/dir that would help diagnose why Clean failed.
		if err := os.RemoveAll(tmpDir); err != nil {

pkg/app/piped/eventwatcher/eventwatcher.go:344

  • The deferred cleanup always calls os.RemoveAll(tmpDir) even when tmpRepo.Clean() fails. This contradicts the PR description (“remove tmpDir after successful repository cleanup”) and can delete the leftover repo/dir that would help diagnose why Clean failed.
		if err := os.RemoveAll(tmpDir); err != nil {
  • Files reviewed: 2/2 changed files
  • Comments generated: 2
  • Review effort level: Lite

Comment on lines +333 to +336
var tmpRepo git.Repo
defer func() {
if tmpRepo != nil {
if err := tmpRepo.Clean(); err != nil {
Comment on lines +324 to +327
var tmpRepo git.Repo
defer func() {
if tmpRepo != nil {
if err := tmpRepo.Clean(); err != nil {
@codecov

codecov Bot commented Sep 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 37.76%. Comparing base (3321879) to head (6f24b68).
⚠️ Report is 3 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7325      +/-   ##
==========================================
+ Coverage   29.75%   37.76%   +8.01%     
==========================================
  Files         601       74     -527     
  Lines       64442     6511   -57931     
==========================================
- Hits        19172     2459   -16713     
+ Misses      43778     3919   -39859     
+ Partials     1492      133    -1359     
Flag Coverage Δ
. ?
.-pkg-app-pipedv1-plugin-analysis ?
.-pkg-app-pipedv1-plugin-ecs 33.64% <ø> (ø)
.-pkg-app-pipedv1-plugin-kubernetes ?
.-pkg-app-pipedv1-plugin-kubernetes_multicluster ?
.-pkg-app-pipedv1-plugin-scriptrun 54.83% <ø> (ø)
.-pkg-app-pipedv1-plugin-terraform 38.46% <ø> (ø)
.-pkg-app-pipedv1-plugin-wait 33.04% <ø> (ø)
.-pkg-app-pipedv1-plugin-waitapproval 52.71% <ø> (ø)
.-pkg-plugin-sdk 50.12% <ø> (ø)
.-tool-actions-gh-release 19.23% <ø> (ø)
.-tool-actions-plan-preview 25.51% <ø> (ø)
.-tool-codegen-protoc-gen-auth ?

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ 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.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants