From f1718d6f87be59f4f432674522c9f5751754714c Mon Sep 17 00:00:00 2001 From: Rishabh Bhandari Date: Mon, 20 Mar 2023 16:45:20 +0530 Subject: [PATCH 1/3] added descriptive error messages Signed-off-by: Rishabh Bhandari --- lib/core/util.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/core/util.js b/lib/core/util.js index ab94bcfe51c..5c5ea63d821 100644 --- a/lib/core/util.js +++ b/lib/core/util.js @@ -48,38 +48,38 @@ function parseURL (url) { url = new URL(url) if (!/^https?:/.test(url.origin || url.protocol)) { - throw new InvalidArgumentError('invalid protocol') + throw new InvalidArgumentError('Invalid URL protocol: the URL must start with `http:` or `https:`.') } return url } if (!url || typeof url !== 'object') { - throw new InvalidArgumentError('invalid url') + throw new InvalidArgumentError('Invalid URL argument: The URL argument must be a non-null object.') } if (url.port != null && url.port !== '' && !Number.isFinite(parseInt(url.port))) { - throw new InvalidArgumentError('invalid port') + throw new InvalidArgumentError('Invalid Port: port must be a valid integer or a string representation of an integer.') } if (url.path != null && typeof url.path !== 'string') { - throw new InvalidArgumentError('invalid path') + throw new InvalidArgumentError('Invalid URL path: the path must be a string or null/undefined.') } if (url.pathname != null && typeof url.pathname !== 'string') { - throw new InvalidArgumentError('invalid pathname') + throw new InvalidArgumentError('Invalid URL pathname: the pathname must be a string or null/undefined.') } if (url.hostname != null && typeof url.hostname !== 'string') { - throw new InvalidArgumentError('invalid hostname') + throw new InvalidArgumentError('Invalid URL hostname: the hostname must be a string or null/undefined.') } if (url.origin != null && typeof url.origin !== 'string') { - throw new InvalidArgumentError('invalid origin') + throw new InvalidArgumentError('iInvalid URL origin: the origin must be a string or null/undefined.') } if (!/^https?:/.test(url.origin || url.protocol)) { - throw new InvalidArgumentError('invalid protocol') + throw new InvalidArgumentError('Invalid URL protocol: the URL must start with `http:` or `https:`.') } if (!(url instanceof URL)) { From 1d13d70acce91427af4cbb6a47d559ff5708d620 Mon Sep 17 00:00:00 2001 From: Rishabh Bhandari Date: Tue, 21 Mar 2023 12:55:41 +0530 Subject: [PATCH 2/3] updating error msgs in tests Signed-off-by: Rishabh Bhandari --- lib/core/util.js | 2 +- test/client-errors.js | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/core/util.js b/lib/core/util.js index 5c5ea63d821..4bb51d37135 100644 --- a/lib/core/util.js +++ b/lib/core/util.js @@ -75,7 +75,7 @@ function parseURL (url) { } if (url.origin != null && typeof url.origin !== 'string') { - throw new InvalidArgumentError('iInvalid URL origin: the origin must be a string or null/undefined.') + throw new InvalidArgumentError('Invalid URL origin: the origin must be a string or null/undefined.') } if (!/^https?:/.test(url.origin || url.protocol)) { diff --git a/test/client-errors.js b/test/client-errors.js index fc6e534c824..35ed7c9d029 100644 --- a/test/client-errors.js +++ b/test/client-errors.js @@ -260,7 +260,7 @@ test('invalid options throws', (t) => { t.fail() } catch (err) { t.type(err, errors.InvalidArgumentError) - t.equal(err.message, 'invalid port') + t.equal(err.message, 'Invalid Port: port must be a valid integer or a string representation of an integer.') } try { @@ -364,7 +364,7 @@ test('invalid options throws', (t) => { t.fail() } catch (err) { t.type(err, errors.InvalidArgumentError) - t.equal(err.message, 'invalid protocol') + t.equal(err.message, 'Invalid URL protocol: the URL must start with `http:` or `https:`.') } try { @@ -374,7 +374,7 @@ test('invalid options throws', (t) => { t.fail() } catch (err) { t.type(err, errors.InvalidArgumentError) - t.equal(err.message, 'invalid hostname') + t.equal(err.message, 'Invalid URL hostname: the hostname must be a string or null/undefined.') } try { @@ -392,7 +392,7 @@ test('invalid options throws', (t) => { t.fail() } catch (err) { t.type(err, errors.InvalidArgumentError) - t.equal(err.message, 'invalid url') + t.equal(err.message, 'Invalid URL argument: The URL argument must be a non-null object.') } try { From 347a51b489ea42dbd65934bacb1081b3737c20b4 Mon Sep 17 00:00:00 2001 From: Rishabh Bhandari Date: Tue, 21 Mar 2023 13:59:50 +0530 Subject: [PATCH 3/3] updated error messages Signed-off-by: Rishabh Bhandari --- lib/core/util.js | 4 ++-- test/client-errors.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/core/util.js b/lib/core/util.js index 4bb51d37135..3939f0d25e5 100644 --- a/lib/core/util.js +++ b/lib/core/util.js @@ -55,11 +55,11 @@ function parseURL (url) { } if (!url || typeof url !== 'object') { - throw new InvalidArgumentError('Invalid URL argument: The URL argument must be a non-null object.') + throw new InvalidArgumentError('Invalid URL: The URL argument must be a non-null object.') } if (url.port != null && url.port !== '' && !Number.isFinite(parseInt(url.port))) { - throw new InvalidArgumentError('Invalid Port: port must be a valid integer or a string representation of an integer.') + throw new InvalidArgumentError('Invalid URL: port must be a valid integer or a string representation of an integer.') } if (url.path != null && typeof url.path !== 'string') { diff --git a/test/client-errors.js b/test/client-errors.js index 35ed7c9d029..936841fbb15 100644 --- a/test/client-errors.js +++ b/test/client-errors.js @@ -260,7 +260,7 @@ test('invalid options throws', (t) => { t.fail() } catch (err) { t.type(err, errors.InvalidArgumentError) - t.equal(err.message, 'Invalid Port: port must be a valid integer or a string representation of an integer.') + t.equal(err.message, 'Invalid URL: port must be a valid integer or a string representation of an integer.') } try { @@ -392,7 +392,7 @@ test('invalid options throws', (t) => { t.fail() } catch (err) { t.type(err, errors.InvalidArgumentError) - t.equal(err.message, 'Invalid URL argument: The URL argument must be a non-null object.') + t.equal(err.message, 'Invalid URL: The URL argument must be a non-null object.') } try {