juanfont/headscale · error · errPolicyTestsFailed

%w:\n%s

Error message

%w:\n%s

What it means

Error "%w:\n%s" thrown in juanfont/headscale.

Source

Thrown at hscontrol/policy/v2/test.go:207

		}

		for _, dst := range res.DenyFail {
			lines = append(lines, fmt.Sprintf("%s -> %s%s: expected DENIED, got ALLOWED", res.Src, dst, protoSuffix))
		}
	}

	return strings.Join(lines, "\n")
}

// wrapTestResult returns nil when every test passed, otherwise wraps the
// rendered failure breakdown in sentinel. errs is passed uncalled so it is
// only evaluated on the failure path.
func wrapTestResult(sentinel error, allPassed bool, errs func() string) error {
	if allPassed {
		return nil
	}

	return fmt.Errorf("%w:\n%s", sentinel, errs())
}

// RunTests evaluates the policy's own `tests` block against the live compiled
// filter and returns a wrapped error when any test fails. Callers that need
// the per-test breakdown can call runPolicyTests directly.
func (pm *PolicyManager) RunTests() error {
	if pm == nil || pm.pol == nil || len(pm.pol.Tests) == 0 {
		return nil
	}

	pm.mu.RLock()
	defer pm.mu.RUnlock()

	results := runPolicyTests(pm.pol, pm.filter, pm.users, pm.nodes)

	return wrapTestResult(errPolicyTestsFailed, results.AllPassed, results.Errors)
}

View on GitHub (pinned to 565fd254d0)

Solutions

  1. Inspect the wrapped error for the underlying cause and correct the failing condition (); retry the operation after fixing the input, configuration, or environment.

Example fix

Inspect the wrapped error for the underlying cause and correct the failing condition (); retry the operation after fixing the input, configuration, or environment.

When it happens

Trigger: Thrown at hscontrol/policy/v2/test.go:207 when the library encounters an invalid state.

Common situations: A policy test failed with detail in the wrapped message. Run the policy check/test command to see which rule expectation did not match.


AI-assisted analysis of juanfont/headscale@565fd254d0 (2026-08-15). Data as JSON: /api/errors/376d0f4499e9f004. Report an issue: GitHub.