Kong/insomnia · error · Error

failed to unparse cookie, the cookie options seems invalid

Error message

failed to unparse cookie, the cookie options seems invalid

What it means

Defensive guard in Cookie.unparseSingle: constructing a Cookie from the supplied options yielded a falsy result, so the options object is considered invalid and cannot be serialized back to a cookie string. Usually follows malformed or incomplete cookie options.

Solutions

  1. Include required fields (at minimum a name/value or valid cookie definition) in CookieOptions
  2. Validate options before calling unparseSingle
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at packages/insomnia-scripting-environment/src/objects/cookies.ts:128 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of Kong/insomnia@d9bb2b0142 (2026-08-26). Data as JSON: /api/errors/6dd91d62ab2801a0. Report an issue: GitHub.

Appendix: source

Thrown at packages/insomnia-scripting-environment/src/objects/cookies.ts:128

      maxAge: cookieObj.maxAge,
      domain: cookieObj.domain || undefined,
      path: cookieObj.path || undefined,
      secure: cookieObj.secure || false,
      httpOnly: cookieObj.httpOnly || false,
      hostOnly,
      session,
      extensions: extensions,
    };
  }

  static stringify(cookie: Cookie) {
    return cookie.toString();
  }

  static unparseSingle(cookieOpt: CookieOptions) {
    const cookie = new Cookie(cookieOpt);
    if (!cookie) {
      throw new Error('failed to unparse cookie, the cookie options seems invalid');
    }
    return cookie.toString();
  }

  static unparse(cookies: Cookie[]) {
    const cookieStrs = cookies.map(cookie => cookie.toString());
    return cookieStrs.join('; ');
  }

  override toString = () => {
    const hostOnlyPart = this.cookie.hostOnly ? '; HostOnly' : '';
    const sessionPart = this.cookie.extensions?.includes('session') ? '; Session' : '';
    const extensionPart =
      this.extensions && this.extensions.length > 0
        ? '; ' + this.extensions.map(ext => `${ext.key}=${ext.value}`).join(';')
        : '';

    return this.cookie.toString() + hostOnlyPart + sessionPart + extensionPart;

View on GitHub (pinned to d9bb2b0142)