grafana/k6 · error
unknown error code: %s
Error message
unknown error code: %s
What it means
AbortRequest maps the given error reason string to a CDP network.ErrorReason via a fixed map (network_manager.go:144-161) and the supplied string is not a key. This is a script validation error: the reason you passed to route.abort() is misspelled or unsupported.
Source
Thrown at internal/js/modules/k6/browser/common/network_manager.go:914
// Authenticate sets HTTP authentication credentials to use.
func (m *NetworkManager) Authenticate(credentials Credentials) error {
m.credentials = credentials
if !credentials.IsEmpty() {
m.userReqInterceptionEnabled = true
}
if err := m.updateProtocolRequestInterception(); err != nil {
return fmt.Errorf("setting authentication credentials: %w", err)
}
return nil
}
func (m *NetworkManager) AbortRequest(requestID fetch.RequestID, errorReason string) error {
m.logger.Debugf("NetworkManager:AbortRequest", "aborting request (id: %s, errorReason: %s)",
requestID, errorReason)
netErrorReason, ok := m.errorReasons[errorReason]
if !ok {
return fmt.Errorf("unknown error code: %s", errorReason)
}
action := fetch.FailRequest(requestID, netErrorReason)
if err := action.Do(cdp.WithExecutor(m.ctx, m.session)); err != nil {
// Avoid logging as error when context is canceled.
// Most probably this happens when trying to fail a site's background request
// while the iteration is ending and therefore the browser context is being closed.
if errors.Is(err, context.Canceled) {
m.logger.Debug("NetworkManager:AbortRequest", "context canceled interrupting request")
} else {
return fmt.Errorf("fail to abort request (id: %s): %w", requestID, err)
}
}
return nil
}
func (m *NetworkManager) ContinueRequest(View on GitHub (pinned to 93accf6570)
Solutions
- Use one of the 14 documented reasons, most commonly 'aborted' for a plain cancel
- Check exact casing and spelling against the list in the k6 browser route.abort() docs (they match the map above)
- If you need a custom outcome, abort with 'aborted' and assert on your own script state instead of inventing a reason
Example fix
// before
await route.abort('cancelled'); // not a valid reason
// after
await route.abort('aborted'); // valid: aborted|accessdenied|addressunreachable|blockedbyclient|blockedbyresponse|connectionaborted|connectionclosed|connectionfailed|connectionrefused|connectionreset|internetdisconnected|namenotresolved|timedout|failed Defensive patterns
Strategy: type-guard
Validate before calling
const REASONS = new Set(['aborted','accessdenied','addressunreachable','blockedbyclient','blockedbyresponse','connectionaborted','connectionclosed','connectionfailed','connectionrefused','connectionreset','internetdisconnected','namenotresolved','timedout','failed']);
Type guard
function isAbortReason(r) {
return typeof r === 'string' && REASONS.has(r);
} Try / catch
if (!isAbortReason(reason)) { throw new Error(`invalid abort reason ${reason}`); }
await route.abort(reason); Prevention
- Centralize abort reasons as constants instead of inline strings
- Run k6 lint/test on scripts that enumerate reasons via a Set lookup
- Remember the list is case-sensitive and fixed — custom reasons are not supported
When it happens
Trigger: Calling route.abort(reason) (or the mapping that invokes AbortRequest) with anything outside the allowed set: aborted, accessdenied, addressunreachable, blockedbyclient, blockedbyresponse, connectionaborted, connectionclosed, connectionfailed, connectionrefused, connectionreset, internetdisconnected, namenotresolved, timedout, failed. Case matters: 'Aborted' or 'aborted ' (with different casing/whitespace) will fail.
Common situations: Copy-pasting Puppeteer/Playwright reason strings that k6 doesn't use; using custom reasons like 'blocked' expecting them to work; typos ('conectionrefused').
Related errors
- fail to abort request (id: %s): %w
- name %q is invalid
- predicate function is not callable
- "handler" argument cannot be nil
- clip area is either empty or outside the viewport
AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15).
Data as JSON: /api/errors/4f6880932cbb52c0.
Report an issue: GitHub.