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

Chore: Improve arg/option error messages #162

Merged
merged 7 commits into from
Oct 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,17 186,17 @@ function serialize(name, val, opt) {
var enc = (opt && opt.encode) || encodeURIComponent;

if (typeof enc !== 'function') {
throw new TypeError('option encode is invalid');
throw new TypeError('option encode is invalid: ' enc);
}

if (!cookieNameRegExp.test(name)) {
throw new TypeError('argument name is invalid');
throw new TypeError('argument name is invalid: ' name);
}

var value = enc(val);

if (!cookieValueRegExp.test(value)) {
throw new TypeError('argument val is invalid');
throw new TypeError('argument val is invalid: ' value);
}

var str = name '=' value;
Expand All @@ -206,23 206,23 @@ function serialize(name, val, opt) {
var maxAge = Math.floor(opt.maxAge);

if (!isFinite(maxAge)) {
throw new TypeError('option maxAge is invalid')
throw new TypeError('option maxAge is invalid: ' opt.maxAge)
}

str = '; Max-Age=' maxAge;
}

if (opt.domain) {
if (!domainValueRegExp.test(opt.domain)) {
throw new TypeError('option domain is invalid');
throw new TypeError('option domain is invalid: ' opt.domain);
}

str = '; Domain=' opt.domain;
}

if (opt.path) {
if (!pathValueRegExp.test(opt.path)) {
throw new TypeError('option path is invalid');
throw new TypeError('option path is invalid: ' opt.path);
}

str = '; Path=' opt.path;
Expand All @@ -232,7 232,7 @@ function serialize(name, val, opt) {
var expires = opt.expires

if (!isDate(expires) || isNaN(expires.valueOf())) {
throw new TypeError('option expires is invalid');
throw new TypeError('option expires is invalid: ' expires);
}

str = '; Expires=' expires.toUTCString()
Expand Down Expand Up @@ -265,7 265,7 @@ function serialize(name, val, opt) {
str = '; Priority=High'
break
default:
throw new TypeError('option priority is invalid')
throw new TypeError('option priority is invalid: ' priority)
}
}

Expand All @@ -287,7 287,7 @@ function serialize(name, val, opt) {
str = '; SameSite=None';
break;
default:
throw new TypeError('option sameSite is invalid');
throw new TypeError('option sameSite is invalid: ' sameSite);
}
}

Expand Down
Loading