fix(sentry): skip "daemon not running" stop/reload errors

This commit is contained in:
Deivid Soto 2026-05-27 16:50:16 +02:00
parent fceadd2009
commit 4d7444ef5b
6 changed files with 90 additions and 12 deletions

View file

@ -9,6 +9,8 @@ import (
gosentry "github.com/getsentry/sentry-go"
"github.com/spf13/pflag"
"github.com/torrentclaw/unarr/internal/agent"
)
// dsn is injected at build time via ldflags. If empty, Sentry is disabled.
@ -63,6 +65,9 @@ func CaptureError(err error, command string) {
}
func isUserInputError(err error) bool {
if errors.Is(err, agent.ErrDaemonNotRunning) {
return true
}
var notExist *pflag.NotExistError
var valueReq *pflag.ValueRequiredError
var invalidVal *pflag.InvalidValueError

View file

@ -1,6 +1,11 @@
package sentry
import "testing"
import (
"fmt"
"testing"
"github.com/torrentclaw/unarr/internal/agent"
)
func TestEnvironment(t *testing.T) {
tests := []struct {
@ -45,3 +50,13 @@ func TestSetUser(t *testing.T) {
// Should not panic without initialization
SetUser("agent-123")
}
func TestIsUserInputErrorDaemonNotRunning(t *testing.T) {
if !isUserInputError(agent.ErrDaemonNotRunning) {
t.Error("ErrDaemonNotRunning should be treated as user-input error")
}
wrapped := fmt.Errorf("stop daemon: %w", agent.ErrDaemonNotRunning)
if !isUserInputError(wrapped) {
t.Error("wrapped ErrDaemonNotRunning should be treated as user-input error")
}
}