fix(errors): prioritize permission errors over 'does not exist' warnings (#11)

filterErr checked 'does not exist' before 'Interactive authentication
required', so when systemd printed both (common for mask/unmask on
non-installed units as a non-root user), the wrong error was returned.

Reorder checks so permission, bus, and masked errors take priority over
existence warnings. Add tests covering mixed-stderr scenarios.

Also:
- CI: install and start nginx so user + root tests pass
- CI: run tests as both user and root for full coverage
- Bump Go 1.26 → 1.26.1
This commit is contained in:
2026-03-06 11:38:03 -05:00
committed by GitHub
parent 7253c912ca
commit 038fbe1a17
5 changed files with 45 additions and 14 deletions

View File

@@ -290,7 +290,7 @@ func TestMask(t *testing.T) {
// try existing unit in user mode as user
{"syncthing", nil, Options{UserMode: true}, true},
// try nonexisting unit in system mode as user
{"nonexistant", ErrDoesNotExist, Options{UserMode: false}, true},
{"nonexistant", ErrInsufficientPermissions, Options{UserMode: false}, true},
// try existing unit in system mode as user
{"nginx", ErrInsufficientPermissions, Options{UserMode: false}, true},
@@ -521,7 +521,7 @@ func TestUnmask(t *testing.T) {
// try existing unit in user mode as user
{"syncthing", nil, Options{UserMode: true}, true},
// try nonexisting unit in system mode as user
{"nonexistant", ErrDoesNotExist, Options{UserMode: false}, true},
{"nonexistant", ErrInsufficientPermissions, Options{UserMode: false}, true},
// try existing unit in system mode as user
{"nginx", ErrInsufficientPermissions, Options{UserMode: false}, true},