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 1 commit
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
Prev Previous commit
Next Next commit
Use old error message format
  • Loading branch information
blakeembrey authored Oct 7, 2024
commit 2c6ebbd0e5c90f057f429a8681bd39ec1ad050ef
18 changes: 9 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,17 113,17 @@ function serialize(name, val, options) {
var enc = opt.encode || encode;

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

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

var value = enc(val);

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

var str = name '=' value;
Expand All @@ -132,23 132,23 @@ function serialize(name, val, options) {
var maxAge = opt.maxAge - 0;

if (isNaN(maxAge) || !isFinite(maxAge)) {
throw new TypeError(opt.maxAge ' is not a valid value for the maxAge option')
throw new TypeError('option maxAge is invalid: ' opt.maxAge)
}

str = '; Max-Age=' Math.floor(maxAge);
}

if (opt.domain) {
if (!fieldContentRegExp.test(opt.domain)) {
throw new TypeError(opt.domain ' is not a valid value for the domain option');
throw new TypeError('option domain is invalid: ' opt.domain);
}

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

if (opt.path) {
if (!fieldContentRegExp.test(opt.path)) {
throw new TypeError(opt.path ' is not a valid value for the path option');
throw new TypeError('option path is invalid: ' opt.path);
}

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

if (!isDate(expires) || isNaN(expires.valueOf())) {
throw new TypeError(expires ' is not a valid value for the expires option');
throw new TypeError('option expires is invalid: ' expires);
}

str = '; Expires=' expires.toUTCString()
Expand Down Expand Up @@ -192,7 192,7 @@ function serialize(name, val, options) {
str = '; Priority=High'
break
default:
throw new TypeError(priority ' is not a valid value for the priority option')
throw new TypeError('option priority is invalid: ' priority)
}
}

Expand All @@ -214,7 214,7 @@ function serialize(name, val, options) {
str = '; SameSite=None';
break;
default:
throw new TypeError(sameSite ' is not a valid value for the sameSite option');
throw new TypeError('option sameSite is invalid: ' sameSite);
}
}

Expand Down