Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

util: fix wrong argument of ERR_INVALID_MIME_SYNTAX #50577

Closed
wants to merge 1 commit into from

Conversation

deokjinkim
Copy link
Contributor

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

node/lib/internal/errors.js

Lines 1419 to 1422 in cde3296

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)

Third argument of ERR_INVALID_MIME_SYNTAX is invalid index
(not string).
@nodejs-github-bot nodejs-github-bot added the needs-ci PRs that need a full CI run. label Nov 6, 2023
@deokjinkim deokjinkim marked this pull request as ready for review November 6, 2023 13:40
@deokjinkim deokjinkim requested a review from bmeck November 6, 2023 13:46
@deokjinkim deokjinkim added the review wanted PRs that need reviews. label Nov 10, 2023
@marco-ippolito
Copy link
Member

maybe we can improve the error message since The MIME syntax for a subtype in "text/javascript," is invalid at 10 is not very informative

@deokjinkim
Copy link
Contributor Author

Close this PR because duplicated to #49711.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-ci PRs that need a full CI run.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants