Skip to content

Commit e206fd5

Browse files
authoredOct 7, 2024··
Improve arg/option error messages (#162)
1 parent d19eaa1 commit e206fd5

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed
 

‎index.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -186,17 +186,17 @@ function serialize(name, val, opt) {
186186
var enc = (opt && opt.encode) || encodeURIComponent;
187187

188188
if (typeof enc !== 'function') {
189-
throw new TypeError('option encode is invalid');
189+
throw new TypeError('option encode is invalid: ' + enc);
190190
}
191191

192192
if (!cookieNameRegExp.test(name)) {
193-
throw new TypeError('argument name is invalid');
193+
throw new TypeError('argument name is invalid: ' + name);
194194
}
195195

196196
var value = enc(val);
197197

198198
if (!cookieValueRegExp.test(value)) {
199-
throw new TypeError('argument val is invalid');
199+
throw new TypeError('argument val is invalid: ' + value);
200200
}
201201

202202
var str = name + '=' + value;
@@ -206,23 +206,23 @@ function serialize(name, val, opt) {
206206
var maxAge = Math.floor(opt.maxAge);
207207

208208
if (!isFinite(maxAge)) {
209-
throw new TypeError('option maxAge is invalid')
209+
throw new TypeError('option maxAge is invalid: ' + opt.maxAge)
210210
}
211211

212212
str += '; Max-Age=' + maxAge;
213213
}
214214

215215
if (opt.domain) {
216216
if (!domainValueRegExp.test(opt.domain)) {
217-
throw new TypeError('option domain is invalid');
217+
throw new TypeError('option domain is invalid: ' + opt.domain);
218218
}
219219

220220
str += '; Domain=' + opt.domain;
221221
}
222222

223223
if (opt.path) {
224224
if (!pathValueRegExp.test(opt.path)) {
225-
throw new TypeError('option path is invalid');
225+
throw new TypeError('option path is invalid: ' + opt.path);
226226
}
227227

228228
str += '; Path=' + opt.path;
@@ -232,7 +232,7 @@ function serialize(name, val, opt) {
232232
var expires = opt.expires
233233

234234
if (!isDate(expires) || isNaN(expires.valueOf())) {
235-
throw new TypeError('option expires is invalid');
235+
throw new TypeError('option expires is invalid: ' + expires);
236236
}
237237

238238
str += '; Expires=' + expires.toUTCString()
@@ -265,7 +265,7 @@ function serialize(name, val, opt) {
265265
str += '; Priority=High'
266266
break
267267
default:
268-
throw new TypeError('option priority is invalid')
268+
throw new TypeError('option priority is invalid: ' + priority)
269269
}
270270
}
271271

@@ -287,7 +287,7 @@ function serialize(name, val, opt) {
287287
str += '; SameSite=None';
288288
break;
289289
default:
290-
throw new TypeError('option sameSite is invalid');
290+
throw new TypeError('option sameSite is invalid: ' + sameSite);
291291
}
292292
}
293293

0 commit comments

Comments
 (0)
Please sign in to comment.