util: fix wrong argument of `ERR_INVALID_MIME_SYNTAX` by deokjinkim · Pull Request #50577 · nodejs/node

Third argument of ERR_INVALID_MIME_SYNTAX is invalid index (not string).

E('ERR_INVALID_MIME_SYNTAX', (production, str, invalidIndex) => {
const msg = invalidIndex !== -1 ? ` at ${invalidIndex}` : '';
return `The MIME syntax for a ${production} in "${str}" is invalid` + msg;
}, TypeError);

When I tested with below example,

const { MIMEType } = require('node:util');
const myMIME = new MIMEType('text/javascript,');

Before

node:internal/mime:73
    throw new ERR_INVALID_MIME_SYNTAX('subtype', str, trimmedSubtype);
    ^

TypeError [ERR_INVALID_MIME_SYNTAX]: The MIME syntax for a subtype in "text/javascript," is invalid at javascript,
    at parseTypeAndSubtype (node:internal/mime:73:11)
    at new MIMEType (node:internal/mime:332:18)

After

node:internal/mime:73
    throw new ERR_INVALID_MIME_SYNTAX('subtype', str, invalidSubtypeIndex);
    ^

TypeError [ERR_INVALID_MIME_SYNTAX]: The MIME syntax for a subtype in "text/javascript," is invalid at 10
    at parseTypeAndSubtype (node:internal/mime:73:11)
    at new MIMEType (node:internal/mime:332:18)