Skip to content

Commit f0cd58d

Browse files
committed
Format error messages
1 parent a4fbb1d commit f0cd58d

File tree

34 files changed

+191
-159
lines changed

34 files changed

+191
-159
lines changed

lib/node_modules/@stdlib/_tools/github/create-issue/lib/validate.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ var isString = require( '@stdlib/assert/is-string' ).isPrimitive;
2626
var isStringArray = require( '@stdlib/assert/is-string-array' ).primitives;
2727
var isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ).isPrimitive;
2828
var isPositiveInteger = require( '@stdlib/assert/is-positive-integer' ).isPrimitive;
29+
var format = require( '@stdlib/string/format' );
2930

3031

3132
// MAIN //
@@ -49,61 +50,61 @@ var isPositiveInteger = require( '@stdlib/assert/is-positive-integer' ).isPrimit
4950
*/
5051
function validate( opts, options ) {
5152
if ( !isObject( options ) ) {
52-
return new TypeError( 'invalid argument. Options argument must be an object. Value: `' + options + '`.' );
53+
return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );
5354
}
5455
opts.token = options.token;
5556
if ( !isString( opts.token ) ) {
56-
return new TypeError( 'invalid option. `token` option must be a string primitive. Option: `' + opts.token + '`.' );
57+
return new TypeError( format( 'invalid option. `%s` option must be a string primitive. Option: `%s`.', 'token', opts.token ) );
5758
}
5859
if ( hasOwnProp( options, 'protocol' ) ) {
5960
opts.protocol = options.protocol;
6061
if ( !isString( opts.protocol ) ) {
61-
return new TypeError( 'invalid option. `protocol` option must be a string primitive. Option: `' + opts.protocol + '`.' );
62+
return new TypeError( format( 'invalid option. `%s` option must be a string primitive. Option: `%s`.', 'protocol', opts.protocol ) );
6263
}
6364
if ( opts.protocol !== 'http' && opts.protocol !== 'https' ) {
64-
return new Error( 'invalid option. `protocol` must be either `http` or `https`. Option: `' + opts.protocol + '`.' );
65+
return new Error( format( 'invalid option. `protocol` must be either `http` or `https`. Option: `%s`.', opts.protocol ) );
6566
}
6667
}
6768
if ( hasOwnProp( options, 'hostname' ) ) {
6869
opts.hostname = options.hostname;
6970
if ( !isString( opts.hostname ) ) {
70-
return new TypeError( 'invalid option. `hostname` option must be a string primitive. Option: `' + opts.hostname + '`.' );
71+
return new TypeError( format( 'invalid option. `%s` option must be a string primitive. Option: `%s`.', 'hostname', opts.hostname ) );
7172
}
7273
}
7374
if ( hasOwnProp( options, 'port' ) ) {
7475
opts.port = options.port;
7576
if ( !isNonNegativeInteger( opts.port ) ) {
76-
return new TypeError( 'invalid option. `port` option must be a nonnegative integer. Option: `' + opts.port + '`.' );
77+
return new TypeError( format( 'invalid option. `%s` option must be a nonnegative integer. Option: `%s`.', 'port', opts.port ) );
7778
}
7879
}
7980
if ( hasOwnProp( options, 'useragent' ) ) {
8081
opts.useragent = options.useragent;
8182
if ( !isString( opts.useragent ) ) {
82-
return new TypeError( 'invalid option. `useragent` option must be a string primitive. Option: `' + opts.useragent + '`.' );
83+
return new TypeError( format( 'invalid option. `%s` option must be a string primitive. Option: `%s`.', 'useragent', opts.useragent ) );
8384
}
8485
}
8586
if ( hasOwnProp( options, 'body' ) ) {
8687
opts.body = options.body;
8788
if ( !isString( opts.body ) ) {
88-
return new TypeError( 'invalid option. `body` option must be a string primitive. Option: `' + opts.body + '`.' );
89+
return new TypeError( format( 'invalid option. `%s` option must be a string primitive. Option: `%s`.', 'body', opts.body ) );
8990
}
9091
}
9192
if ( hasOwnProp( options, 'assignees' ) ) {
9293
opts.assignees = options.assignees;
9394
if ( !isStringArray( opts.assignees ) ) {
94-
return new TypeError( 'invalid option. `assignees` option must be an array of string primitives. Option: `' + opts.assignees + '`.' );
95+
return new TypeError( format( 'invalid option. `%s` option must be an array of string primitives. Option: `%s`.', 'assignees', opts.assignees ) );
9596
}
9697
}
9798
if ( hasOwnProp( options, 'milestone' ) ) {
9899
opts.milestone = options.milestone;
99100
if ( !isPositiveInteger( opts.milestone ) ) {
100-
return new TypeError( 'invalid option. `milestone` option must be a positive integer. Option: `' + opts.milestone + '`.' );
101+
return new TypeError( format( 'invalid option. `%s` option must be a positive integer. Option: `%s`.', 'milestone', opts.milestone ) );
101102
}
102103
}
103104
if ( hasOwnProp( options, 'labels' ) ) {
104105
opts.labels = options.labels;
105106
if ( !isStringArray( opts.labels ) ) {
106-
return new TypeError( 'invalid option. `labels` option must be an array of string primitives. Option: `' + opts.labels + '`.' );
107+
return new TypeError( format( 'invalid option. `%s` option must be an array of string primitives. Option: `%s`.', 'labels', opts.labels ) );
107108
}
108109
}
109110
return null;

lib/node_modules/@stdlib/_tools/github/create-repo/lib/validate.js

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
2626
var isObject = require( '@stdlib/assert/is-object' );
2727
var isString = require( '@stdlib/assert/is-string' ).isPrimitive;
2828
var isURI = require( '@stdlib/assert/is-uri' );
29+
var format = require( '@stdlib/string/format' );
2930

3031

3132
// MAIN //
@@ -56,106 +57,106 @@ var isURI = require( '@stdlib/assert/is-uri' );
5657
*/
5758
function validate( opts, options ) {
5859
if ( !isObject( options ) ) {
59-
return new TypeError( 'invalid argument. Options argument must be an object. Value: `' + options + '`.' );
60+
return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );
6061
}
6162
opts.token = options.token;
6263
if ( !isString( opts.token ) ) {
63-
return new TypeError( 'invalid option. `token` option must be a string primitive. Option: `' + opts.token + '`.' );
64+
return new TypeError( format( 'invalid option. `%s` option must be a string primitive. Option: `%s`.', 'token', opts.token ) );
6465
}
6566
if ( hasOwnProp( options, 'useragent' ) ) {
6667
opts.useragent = options.useragent;
6768
if ( !isString( opts.useragent ) ) {
68-
return new TypeError( 'invalid option. `useragent` option must be a string primitive. Option: `' + opts.useragent + '`.' );
69+
return new TypeError( format( 'invalid option. `%s` option must be a string primitive. Option: `%s`.', 'useragent', opts.useragent ) );
6970
}
7071
}
7172
if ( hasOwnProp( options, 'org' ) ) {
7273
opts.org = options.org;
7374
if ( !isString( opts.org ) ) {
74-
return new TypeError( 'invalid option. `org` option must be a string primitive. Option: `' + opts.org + '`.' );
75+
return new TypeError( format( 'invalid option. `%s` option must be a string primitive. Option: `%s`.', 'org', opts.org ) );
7576
}
7677
}
7778
if ( hasOwnProp( options, 'desc' ) ) {
7879
opts.desc = options.desc;
7980
if ( !isString( opts.desc ) ) {
80-
return new TypeError( 'invalid option. `desc` option must be a string primitive. Option: `' + opts.desc + '`.' );
81+
return new TypeError( format( 'invalid option. `%s` option must be a string primitive. Option: `%s`.', 'desc', opts.desc ) );
8182
}
8283
}
8384
if ( hasOwnProp( options, 'homepage' ) ) {
8485
opts.homepage = options.homepage;
8586
if ( !isURI( opts.homepage ) ) {
86-
return new TypeError( 'invalid option. `homepage` option must be a valid URI. Option: `' + opts.homepage + '`.' );
87+
return new TypeError( format( 'invalid option. `%s` option must be a valid URI. Option: `%s`.', 'homepage', opts.homepage ) );
8788
}
8889
}
8990
if ( hasOwnProp( options, 'team' ) ) {
9091
opts.team = options.team;
9192
if ( !isNonNegativeInteger( opts.team ) ) {
92-
return new TypeError( 'invalid option. `team` option must be a nonnegative integer. Option: `' + opts.team + '`.' );
93+
return new TypeError( format( 'invalid option. `%s` option must be a nonnegative integer. Option: `%s`.', 'team', opts.team ) );
9394
}
9495
}
9596
if ( hasOwnProp( options, 'gitignore' ) ) {
9697
opts.gitignore = options.gitignore;
9798
if ( !isString( opts.gitignore ) ) {
98-
return new TypeError( 'invalid option. `gitignore` option must be a string primitive. Option: `' + opts.gitignore + '`.' );
99+
return new TypeError( format( 'invalid option. `%s` option must be a string primitive. Option: `%s`.', 'gitignore', opts.gitignore ) );
99100
}
100101
}
101102
if ( hasOwnProp( options, 'license' ) ) {
102103
opts.license = options.license;
103104
if ( !isString( opts.license ) ) {
104-
return new TypeError( 'invalid option. `license` option must be a string primitive. Option: `' + opts.license + '`.' );
105+
return new TypeError( format( 'invalid option. `%s` option must be a string primitive. Option: `%s`.', 'license', opts.license ) );
105106
}
106107
}
107108
if ( hasOwnProp( options, 'private' ) ) {
108109
opts.private = options.private;
109110
if ( !isBoolean( opts.private ) ) {
110-
return new TypeError( 'invalid option. `private` option must be a boolean primitive. Option: `' + opts.private + '`.' );
111+
return new TypeError( format( 'invalid option. `%s` option must be a boolean primitive. Option: `%s`.', 'private', opts.private ) );
111112
}
112113
}
113114
if ( hasOwnProp( options, 'issues' ) ) {
114115
opts.issues = options.issues;
115116
if ( !isBoolean( opts.issues ) ) {
116-
return new TypeError( 'invalid option. `issues` option must be a boolean primitive. Option: `' + opts.issues + '`.' );
117+
return new TypeError( format( 'invalid option. `%s` option must be a boolean primitive. Option: `%s`.', 'issues', opts.issues ) );
117118
}
118119
}
119120
if ( hasOwnProp( options, 'projects' ) ) {
120121
opts.projects = options.projects;
121122
if ( !isBoolean( opts.projects ) ) {
122-
return new TypeError( 'invalid option. `projects` option must be a boolean primitive. Option: `' + opts.wiki + '`.' );
123+
return new TypeError( format( 'invalid option. `%s` option must be a boolean primitive. Option: `%s`.', 'projects', opts.projects ) );
123124
}
124125
}
125126
if ( hasOwnProp( options, 'wiki' ) ) {
126127
opts.wiki = options.wiki;
127128
if ( !isBoolean( opts.wiki ) ) {
128-
return new TypeError( 'invalid option. `wiki` option must be a boolean primitive. Option: `' + opts.wiki + '`.' );
129+
return new TypeError( format( 'invalid option. `%s` option must be a boolean primitive. Option: `%s`.', 'wiki', opts.wiki ) );
129130
}
130131
}
131132
if ( hasOwnProp( options, 'downloads' ) ) {
132133
opts.downloads = options.downloads;
133134
if ( !isBoolean( opts.downloads ) ) {
134-
return new TypeError( 'invalid option. `downloads` option must be a boolean primitive. Option: `' + opts.downloads + '`.' );
135+
return new TypeError( format( 'invalid option. `%s` option must be a boolean primitive. Option: `%s`.', 'downloads', opts.downloads ) );
135136
}
136137
}
137138
if ( hasOwnProp( options, 'init' ) ) {
138139
opts.init = options.init;
139140
if ( !isBoolean( opts.init ) ) {
140-
return new TypeError( 'invalid option. `init` option must be a boolean primitive. Option: `' + opts.init + '`.' );
141+
return new TypeError( format( 'invalid option. `%s` option must be a boolean primitive. Option: `%s`.', 'init', opts.init ) );
141142
}
142143
}
143144
if ( hasOwnProp( options, 'allowSquashMerge' ) ) {
144145
opts.allowSquashMerge = options.allowSquashMerge;
145146
if ( !isBoolean( opts.allowSquashMerge ) ) {
146-
return new TypeError( 'invalid option. `allowSquashMerge` option must be a boolean primitive. Option: `' + opts.allowSquashMerge + '`.' );
147+
return new TypeError( format( 'invalid option. `%s` option must be a boolean primitive. Option: `%s`.', 'allowSquashMerge', opts.allowSquashMerge ) );
147148
}
148149
}
149150
if ( hasOwnProp( options, 'allowMergeCommit' ) ) {
150151
opts.allowMergeCommit = options.allowMergeCommit;
151152
if ( !isBoolean( opts.allowMergeCommit ) ) {
152-
return new TypeError( 'invalid option. `allowMergeCommit` option must be a boolean primitive. Option: `' + opts.allowMergeCommit + '`.' );
153+
return new TypeError( format( 'invalid option. `%s` option must be a boolean primitive. Option: `%s`.', 'allowMergeCommit', opts.allowMergeCommit ) );
153154
}
154155
}
155156
if ( hasOwnProp( options, 'allowRebaseMerge' ) ) {
156157
opts.allowRebaseMerge = options.allowRebaseMerge;
157158
if ( !isBoolean( opts.allowRebaseMerge ) ) {
158-
return new TypeError( 'invalid option. `allowRebaseMerge` option must be a boolean primitive. Option: `' + opts.allowRebaseMerge + '`.' );
159+
return new TypeError( format( 'invalid option. `%s` option must be a boolean primitive. Option: `%s`.', 'allowRebaseMerge', opts.allowRebaseMerge ) );
159160
}
160161
}
161162
return null;

lib/node_modules/@stdlib/_tools/github/org-repos/lib/validate.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
var hasOwnProp = require( '@stdlib/assert/has-own-property' );
2424
var isObject = require( '@stdlib/assert/is-object' );
2525
var isString = require( '@stdlib/assert/is-string' ).isPrimitive;
26+
var format = require( '@stdlib/string/format' );
2627

2728

2829
// MAIN //
@@ -40,28 +41,28 @@ var isString = require( '@stdlib/assert/is-string' ).isPrimitive;
4041
*/
4142
function validate( opts, options ) {
4243
if ( !isObject( options ) ) {
43-
return new TypeError( 'invalid argument. Options argument must be an object. Value: `' + options + '`.' );
44+
return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );
4445
}
4546
opts.org = options.org;
4647
if ( !isString( opts.org ) ) {
47-
return new TypeError( 'invalid option. Organization name option must be a string primitive. Option: `' + opts.org + '`.' );
48+
return new TypeError( format( 'invalid option. `org` organization name option must be a string primitive. Option: `%s`.', opts.org ) );
4849
}
4950
if ( hasOwnProp( options, 'type' ) ) {
5051
opts.type = options.type;
5152
if ( !isString( opts.type ) ) {
52-
return new TypeError( 'invalid option. Type option must be a string primitive. Option: `' + opts.type + '`.' );
53+
return new TypeError( format( 'invalid option. `%s` option must be a string primitive. Option: `%s`.', 'type', opts.type ) );
5354
}
5455
}
5556
if ( hasOwnProp( options, 'token' ) ) {
5657
opts.token = options.token;
5758
if ( !isString( opts.token ) ) {
58-
return new TypeError( 'invalid option. Token option must be a string primitive. Option: `' + opts.token + '`.' );
59+
return new TypeError( format( 'invalid option. `%s` option must be a string primitive. Option: `%s`.', 'token', opts.token ) );
5960
}
6061
}
6162
if ( hasOwnProp( options, 'useragent' ) ) {
6263
opts.useragent = options.useragent;
6364
if ( !isString( opts.useragent ) ) {
64-
return new TypeError( 'invalid option. User agent option must be a string primitive. Option: `' + opts.useragent + '`.' );
65+
return new TypeError( format( 'invalid option. `%s` option must be a string primitive. Option: `%s`.', 'useragent', opts.useragent ) );
6566
}
6667
}
6768
return null;

lib/node_modules/@stdlib/_tools/github/rank-followers/lib/validate.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
var hasOwnProp = require( '@stdlib/assert/has-own-property' );
2424
var isObject = require( '@stdlib/assert/is-object' );
2525
var isString = require( '@stdlib/assert/is-string' ).isPrimitive;
26+
var format = require( '@stdlib/string/format' );
2627

2728

2829
// MAIN //
@@ -40,30 +41,30 @@ var isString = require( '@stdlib/assert/is-string' ).isPrimitive;
4041
*/
4142
function validate( opts, options ) {
4243
if ( !isObject( options ) ) {
43-
return new TypeError( 'invalid argument. Options argument must be an object. Value: `' + options + '`.' );
44+
return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );
4445
}
4546
if ( hasOwnProp( options, 'token' ) ) {
4647
opts.token = options.token;
4748
if ( !isString( opts.token ) ) {
48-
return new TypeError( 'invalid option. Token option must be a string primitive. Option: `' + opts.token + '`.' );
49+
return new TypeError( format( 'invalid option. `%s` option must be a string primitive. Option: `%s`.', 'token', opts.token ) );
4950
}
5051
}
5152
if ( hasOwnProp( options, 'username' ) ) {
5253
opts.username = options.username;
5354
if ( !isString( opts.username ) ) {
54-
return new TypeError( 'invalid option. Username option must be a string primitive. Option: `' + opts.username + '`.' );
55+
return new TypeError( format( 'invalid option. `%s` option must be a string primitive. Option: `%s`.', 'username', opts.username ) );
5556
}
5657
}
5758
if ( hasOwnProp( options, 'useragent' ) ) {
5859
opts.useragent = options.useragent;
5960
if ( !isString( opts.useragent ) ) {
60-
return new TypeError( 'invalid option. User agent option must be a string primitive. Option: `' + opts.useragent + '`.' );
61+
return new TypeError( format( 'invalid option. `%s` option must be a string primitive. Option: `%s`.', 'useragent', opts.useragent ) );
6162
}
6263
}
6364
if ( hasOwnProp( options, 'method' ) ) {
6465
opts.method = options.method;
6566
if ( !isString( opts.method ) ) {
66-
return new TypeError( 'invalid option. Method option must be a string primitive. Option: `' + opts.method + '`.' );
67+
return new TypeError( format( 'invalid option. `%s` option must be a string primitive. Option: `%s`.', 'method', opts.method ) );
6768
}
6869
}
6970
return null;

lib/node_modules/@stdlib/_tools/github/user-orgs/lib/validate.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
var hasOwnProp = require( '@stdlib/assert/has-own-property' );
2424
var isObject = require( '@stdlib/assert/is-object' );
2525
var isString = require( '@stdlib/assert/is-string' ).isPrimitive;
26+
var format = require( '@stdlib/string/format' );
2627

2728

2829
// MAIN //
@@ -40,30 +41,30 @@ var isString = require( '@stdlib/assert/is-string' ).isPrimitive;
4041
*/
4142
function validate( opts, options ) {
4243
if ( !isObject( options ) ) {
43-
return new TypeError( 'invalid argument. Options argument must be an object. Value: `' + options + '`.' );
44+
return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );
4445
}
4546
if ( hasOwnProp( options, 'token' ) ) {
4647
opts.token = options.token;
4748
if ( !isString( opts.token ) ) {
48-
return new TypeError( 'invalid option. Token option must be a string primitive. Option: `' + opts.token + '`.' );
49+
return new TypeError( format( 'invalid option. `%s` option must be a string primitive. Option: `%s`.', 'token', opts.token ) );
4950
}
5051
}
5152
if ( hasOwnProp( options, 'username' ) ) {
5253
opts.username = options.username;
5354
if ( !isString( opts.username ) ) {
54-
return new TypeError( 'invalid option. Username option must be a string primitive. Option: `' + opts.username + '`.' );
55+
return new TypeError( format( 'invalid option. `%s` option must be a string primitive. Option: `%s`.', 'username', opts.username ) );
5556
}
5657
}
5758
if ( hasOwnProp( options, 'useragent' ) ) {
5859
opts.useragent = options.useragent;
5960
if ( !isString( opts.useragent ) ) {
60-
return new TypeError( 'invalid option. User agent option must be a string primitive. Option: `' + opts.useragent + '`.' );
61+
return new TypeError( format( 'invalid option. `%s` option must be a string primitive. Option: `%s`.', 'useragent', opts.useragent ) );
6162
}
6263
}
6364
if ( hasOwnProp( options, 'state' ) ) {
6465
opts.state = options.state;
6566
if ( !isString( opts.state ) ) {
66-
return new TypeError( 'invalid option. State option must be a string primitive. Option: `' + opts.state + '`.' );
67+
return new TypeError( format( 'invalid option. `%s` option must be a string primitive. Option: `%s`.', 'state', opts.state ) );
6768
}
6869
}
6970
return null;

0 commit comments

Comments
 (0)