DopplerHQ / DopplerHQ/cli

[BUG] Close() errors silently ignored in secrets.go

Open
#524 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Go
Stars
396
Forks
83
Avg merge
1d 2h
Merged PRs (30d)
3

Description

Description

In pkg/controllers/secrets.go at line 241, file close errors are explicitly ignored using _ = f.Close(). This can mask important errors and cause data loss.

Impact

When Close() fails, it often means:

  • Data wasn't fully written to disk
  • File system errors occurred (disk full, permissions, etc.)
  • The operation that was supposed to succeed actually failed

By ignoring these errors, users might think their data was saved when it wasn't.

Location

File: pkg/controllers/secrets.go
Line: 241

_ = f.Close()  // ← Error silently ignored

Suggested Fix

Check and handle the error appropriately:

if err := f.Close(); err != nil {
    utils.HandleError(err, "Unable to close file", true)
}

Or if it's in a function that returns an error:

if closeErr := f.Close(); closeErr != nil {
    return fmt.Errorf("failed to close file: %w", closeErr)
}

Why This Matters

According to the Go FAQ on error handling:

Close can return an error if, for instance, the file descriptor was already closed, or if there were unflushed writes that couldn't be completed.

This is especially critical for file writes, as Close() may flush buffered data. Ignoring the error means you might lose data without knowing it.

Additional Context

This issue was found during a code audit focused on error handling best practices. While it may not cause problems in most cases, proper error handling is a defensive programming practice that prevents silent failures.

Reference: Go Error Handling Best Practices

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at line 241 of pkg/controllers/secrets.go and inspect the surrounding function to see whether it returns errors or uses the suggested error handler. Confirm how nearby controller code handles file-close failures. Done means the close error is no longer silently ignored and the failure reaches the caller or is handled consistently.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
cli, security
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.