fix: handle error returns from os.Unsetenv and file.Close (errcheck)

Fixed the first five errcheck linter errors:
- Added error handling for os.Unsetenv in cli_test.go
- Added error handling for file.Close() in crypto.go (4 instances)
This commit is contained in:
Jeffrey Paul 2025-07-09 06:16:13 -07:00
parent 2256a37b72
commit 11e43542cf
2 changed files with 5 additions and 5 deletions

View File

@ -47,7 +47,7 @@ func TestDetermineStateDir(t *testing.T) {
}
// Test with custom config dir
os.Unsetenv(secret.EnvStateDir)
_ = os.Unsetenv(secret.EnvStateDir)
customConfigDir := "/custom-config"
stateDir = secret.DetermineStateDir(customConfigDir)
expectedDir := filepath.Join(customConfigDir, secret.AppID)

View File

@ -128,7 +128,7 @@ func (cli *Instance) Encrypt(secretName, inputFile, outputFile string) error {
if err != nil {
return fmt.Errorf("failed to open input file: %w", err)
}
defer file.Close()
defer func() { _ = file.Close() }()
input = file
}
@ -139,7 +139,7 @@ func (cli *Instance) Encrypt(secretName, inputFile, outputFile string) error {
if err != nil {
return fmt.Errorf("failed to create output file: %w", err)
}
defer file.Close()
defer func() { _ = file.Close() }()
output = file
}
@ -214,7 +214,7 @@ func (cli *Instance) Decrypt(secretName, inputFile, outputFile string) error {
if err != nil {
return fmt.Errorf("failed to open input file: %w", err)
}
defer file.Close()
defer func() { _ = file.Close() }()
input = file
}
@ -225,7 +225,7 @@ func (cli *Instance) Decrypt(secretName, inputFile, outputFile string) error {
if err != nil {
return fmt.Errorf("failed to create output file: %w", err)
}
defer file.Close()
defer func() { _ = file.Close() }()
output = file
}