Skip to content

Commit

Permalink
A change in error messages (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
omrilotan authored Sep 22, 2019
1 parent 9de5291 commit 285d974
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ class SDC {

if (rate) {
if (typeof rate !== 'number') {
throw new TypeError(`Expected 'rate' to be a number, instead got a ${typeof rate}`);
throw new TypeError(`Expected 'rate' to be a number, instead got ${rate} (${typeof rate})`);
}
if (rate > 1) {
throw new TypeError(`Expected 'rate' to be a number between 0 and 1, instead got ${rate}`);
Expand Down
8 changes: 4 additions & 4 deletions lib/formatter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const schemes = require('../../schemes');
module.exports = function formatter({prefix, sanitise = sanitiser, scheme = 'datadog'} = {}) {
if (prefix) {
if (typeof prefix !== 'string') {
throw new TypeError(`Expected 'prefix' to be a string, instead got a ${typeof prefix}`);
throw new TypeError(`Expected 'prefix' to be a string, instead got ${prefix} (${typeof prefix})`);
}
if (!letterLeading(prefix)) {
throw new Error(`Prefix must start with an alphabetical character (${prefix}).`);
Expand All @@ -25,7 +25,7 @@ module.exports = function formatter({prefix, sanitise = sanitiser, scheme = 'dat
// If "sanitise" is falsy, it should do nothing to the input
sanitise = sanitise || ((string) => string);
if (typeof sanitise !== 'function') {
throw new TypeError(`Expected 'sanitise' to be a function, instead got a ${typeof sanitise}`);
throw new TypeError(`Expected 'sanitise' to be a function, instead got ${sanitise} (${typeof sanitise})`);
}

if (typeof scheme === 'string') {
Expand Down Expand Up @@ -65,7 +65,7 @@ module.exports = function formatter({prefix, sanitise = sanitiser, scheme = 'dat
throw new RangeError(`Expected 'type' to be one of ${Object.keys(types).join(', ')}, instead got ${type}`);
}
if (typeof key !== 'string') {
throw new TypeError(`Expected 'key' to be a string, instead got a ${typeof key}`);
throw new TypeError(`Expected 'key' to be a string, instead got ${key} (${typeof key})`);
}
if (!prefix && !letterLeading(key)) {
throw new Error(`Expected 'key' to start with an alphabetical character (${key}).`);
Expand All @@ -77,7 +77,7 @@ module.exports = function formatter({prefix, sanitise = sanitiser, scheme = 'dat
value = Number(process.hrtime.bigint() - value) / 1e6;
}
if (typeof value !== 'number' || !isNumber(value)) {
throw new TypeError(`Expected 'value' to be a number, instead got a ${typeof value}`);
throw new TypeError(`Expected 'value' to be a number, instead got ${value} (${typeof value})`);
}

if (prefix) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@fiverr/statsd-client",
"version": "0.2.2",
"version": "0.2.3",
"description": "📈 A feature packed, highly customisable StatsD client",
"keywords": [
"StatsD",
Expand Down

0 comments on commit 285d974

Please # to comment.