Handle pacman -Qdtq exit code 1 as non-error

pacman -Qdtq exits with code 1 when there are no orphans, which is not an error condition. Handle this gracefully by returning nil instead of an error.
This commit is contained in:
AI Bot
2026-04-19 11:08:32 +02:00
committed by Riyyi
parent c90d2e8916
commit fdd9ecb3a5
+10
View File
@@ -1,6 +1,8 @@
package read package read
import ( import (
"bytes"
"errors"
"fmt" "fmt"
"os" "os"
"os/exec" "os/exec"
@@ -38,8 +40,16 @@ func ListOrphans() ([]string, error) {
log.Debug("ListOrphans: starting...") log.Debug("ListOrphans: starting...")
cmd := exec.Command("pacman", "-Qdtq") cmd := exec.Command("pacman", "-Qdtq")
var stderr bytes.Buffer
cmd.Stderr = &stderr
output, err := cmd.Output() output, err := cmd.Output()
if err != nil { if err != nil {
// pacman -Qdtq exits 1 when there are no orphans, this isnt an error
var exitErr *exec.ExitError
if errors.As(err, &exitErr) && exitErr.ExitCode() == 1 && stderr.Len() == 0 {
return nil, nil
}
return nil, err return nil, err
} }