{"record":{"id":"321b7a8987b9b5af","repo":"grafana/k6","slug":"cookie-is-null","errorCode":null,"errorMessage":"cookie: is null","messagePattern":"cookie: is null","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"js/modules/k6/http/cookiejar.go","lineNumber":105,"sourceCode":"func (j CookieJar) Clear(url string) error {\n\tu, err := neturl.Parse(url)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tcookies := j.Jar.Cookies(u)\n\tfor _, c := range cookies {\n\t\tc.MaxAge = -1\n\t}\n\tj.Jar.SetCookies(u, cookies)\n\n\treturn nil\n}\n\n// Delete cookies for a particular URL\nfunc (j CookieJar) Delete(url, name string) error {\n\tif name == \"\" {\n\t\treturn errors.New(\"cookie: is null\")\n\t}\n\n\tu, err := neturl.Parse(url)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tc := http.Cookie{Name: name, MaxAge: -1}\n\tj.Jar.SetCookies(u, []*http.Cookie{&c})\n\n\treturn nil\n}\n","sourceCodeStart":87,"sourceCodeEnd":118,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/js/modules/k6/http/cookiejar.go#L87-L118","documentation":"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.","triggerScenarios":"Calling jar.delete(url) with only one argument (the missing name arrives as the empty string), or passing a variable that evaluates to ''.","commonSituations":"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.","solutions":["Pass the cookie name explicitly: jar.delete(url, 'session_id')","If the name comes from data, default or validate it first: if (!name) throw new Error('cookie name required')","To drop all cookies for a URL, iterate jar.cookies(url) and delete each by name"],"exampleFix":"// before\njar.delete('https://example.com');\n\n// after\njar.delete('https://example.com', 'session_id');","handlingStrategy":"validation","validationCode":"function deleteCookie(jar, url, name) {\n  if (!name) throw new Error(`cookie name required to delete on ${url}`);\n  return jar.delete(url, name);\n}","typeGuard":"const isNonEmptyString = (s) => typeof s === 'string' && s.length > 0;","tryCatchPattern":null,"preventionTips":["Never call jar.delete(url) with a single argument","Default or validate names parsed from headers/data before deleting","To clear a URL's cookies, loop jar.cookies(url) and delete each by name"],"tags":["javascript","http","cookies","cookiejar","validation"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}