grafana/k6 · error

method is invalid

Error message

method %q is invalid

What it means

Validation guard in MetricEvent.Tag: a Match entry's method field (uppercased after trimming) is not one of the accepted HTTP verbs (GET, POST, PUT, etc.). The offending input is the 'method' value inside a metricEventPatterns match.

Solutions

  1. Use a standard HTTP method name in the match's method field
  2. Leave method empty to match all methods
  3. Correct typos and casing is flexible but the name must be a real verb
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at internal/js/modules/k6/browser/common/page.go:456 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of grafana/k6@3fcf5388d7 (2026-08-18). Data as JSON: /api/errors/a63e0f2e76d0882b. Report an issue: GitHub.

Appendix: source

Thrown at internal/js/modules/k6/browser/common/page.go:458

// Tag will find the first match given the URLTagPatterns and the URL from
// the metric tag and update the name field.
func (e *MetricEvent) Tag(rm RegExMatcher, matches TagMatches) error {
	name := strings.TrimSpace(matches.TagName)
	if name == "" {
		return fmt.Errorf("name %q is invalid", matches.TagName)
	}

	for _, m := range matches.Matches {
		// Validate the request method type if it has been assigned in a Match.
		method := strings.TrimSpace(m.Method)
		if method != "" {
			method = strings.ToUpper(method)
			switch method {
			case http.MethodGet, http.MethodPost, http.MethodPut, http.MethodDelete, http.MethodPatch,
				http.MethodHead, http.MethodOptions, http.MethodConnect, http.MethodTrace:
			default:
				return fmt.Errorf("method %q is invalid", m.Method)
			}

			if method != e.method {
				continue
			}
		}

		// matchesRegex is a function that will perform the regex test in the Sobek
		// runtime.
		matched, err := rm(m.URLRegEx, e.url)
		if err != nil {
			return err
		}

		if matched {
			e.isUserURLTagNameExist = true
			e.userProvidedURLTagName = name
			return nil

View on GitHub (pinned to 3fcf5388d7)