grafana/k6 · error

cookie: is null

Error message

cookie: is null

What it means

CookieJar.Delete(url, name) in k6's http module requires a non-empty cookie name; an empty name is rejected up front with this (admittedly terse) message before any URL parsing or cookie mutation happens. The name identifies which cookie to expire (MaxAge -1) for the given URL.

Source

Thrown at js/modules/k6/http/cookiejar.go:105

func (j CookieJar) Clear(url string) error {
	u, err := neturl.Parse(url)
	if err != nil {
		return err
	}

	cookies := j.Jar.Cookies(u)
	for _, c := range cookies {
		c.MaxAge = -1
	}
	j.Jar.SetCookies(u, cookies)

	return nil
}

// Delete cookies for a particular URL
func (j CookieJar) Delete(url, name string) error {
	if name == "" {
		return errors.New("cookie: is null")
	}

	u, err := neturl.Parse(url)
	if err != nil {
		return err
	}

	c := http.Cookie{Name: name, MaxAge: -1}
	j.Jar.SetCookies(u, []*http.Cookie{&c})

	return nil
}

View on GitHub (pinned to 93accf6570)

Solutions

  1. Pass the cookie name explicitly: jar.delete(url, 'session_id')
  2. If the name comes from data, default or validate it first: if (!name) throw new Error('cookie name required')
  3. To drop all cookies for a URL, iterate jar.cookies(url) and delete each by name

Example fix

// before
jar.delete('https://example.com');

// after
jar.delete('https://example.com', 'session_id');
Defensive patterns

Strategy: validation

Validate before calling

function deleteCookie(jar, url, name) {
  if (!name) throw new Error(`cookie name required to delete on ${url}`);
  return jar.delete(url, name);
}

Type guard

const isNonEmptyString = (s) => typeof s === 'string' && s.length > 0;

Prevention

When it happens

Trigger: Calling jar.delete(url) with only one argument (the missing name arrives as the empty string), or passing a variable that evaluates to ''.

Common situations: Assuming delete(url) clears all cookies for a URL; name computed from a response header that was absent; destructuring or optional fields yielding undefined/'' in the script.

Related errors


AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15). Data as JSON: /api/errors/321b7a8987b9b5af. Report an issue: GitHub.