Skip to content

Commit f70ce40

Browse files
authored
fix: format errors properly (#194)
* Format errors properly with wp I just faced the issue with superstruct errors in webpack-nano. Error message is not shown. In this diff I created new instance with builtin error constructor. ``` ⬢ wps: An option was passed to WebpackPluginServe that is not valid Error: at new StructError (.../node_modules/superstruct/src/struct.ts:71:18) at validate (.../node_modules/superstruct/src/struct.ts:170:19) at validate (.../node_modules/webpack-plugin-serve/lib/validate.js:63:28) at new WebpackPluginServe (.../node_modules/webpack-plugin-serve/lib/index.js:58:19) at Object.<anonymous> (.../realadvisor.crm/webpack.config.js:79:5) at Module._compile (internal/modules/cjs/loader.js:1076:30) at Module._compile (.../node_modules/pirates/lib/index.js:99:24) at Module._extensions..js (internal/modules/cjs/loader.js:1097:10) at Object.newLoader [as .js] (.../node_modules/pirates/lib/index.js:104:7) at Module.load (internal/modules/cjs/loader.js:941:32) ``` ``` ⬢ wps: An option was passed to WebpackPluginServe that is not valid TypeError: Expected a value of type `port | promise-like` for `port` but received `"5000"`. at validate (.../node_modules/webpack-plugin-serve/lib/validate.js:74:23) at new WebpackPluginServe (.../node_modules/webpack-plugin-serve/lib/index.js:58:19) at Object.<anonymous> (.../realadvisor.crm/webpack.config.js:79:5) at Module._compile (internal/modules/cjs/loader.js:1076:30) at Module._compile (.../node_modules/pirates/lib/index.js:99:24) at Module._extensions..js (internal/modules/cjs/loader.js:1097:10) at Object.newLoader [as .js] (.../node_modules/pirates/lib/index.js:104:7) at Module.load (internal/modules/cjs/loader.js:941:32) at Function.Module._load (internal/modules/cjs/loader.js:782:14) at Module.require (internal/modules/cjs/loader.js:965:19) ``` * Update snapshots * Upgrade superstruct
1 parent 35fb6c4 commit f70ce40

File tree

5 files changed

+25
-20
lines changed

5 files changed

+25
-20
lines changed

lib/validate.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@
99
included in all copies or substantial portions of this Source Code Form.
1010
*/
1111
const {
12-
refinement,
12+
refine,
1313
any,
1414
nullable,
1515
type,
1616
partial,
1717
array,
1818
union,
19-
number,
19+
integer,
20+
max,
2021
boolean,
2122
string,
2223
func,
@@ -26,9 +27,7 @@ const {
2627
} = require('superstruct');
2728
const isPromise = require('is-promise');
2829

29-
const promise = refinement(any(), 'promise-like', (value) => isPromise(value));
30-
31-
const port = refinement(number(), 'port', (value) => Number.isInteger(value) && value <= 65535);
30+
const promise = refine(any(), 'promise-like', (value) => isPromise(value));
3231

3332
module.exports = {
3433
validate(options) {
@@ -50,7 +49,7 @@ module.exports = {
5049
log: partial({ level: string(), timestamp: boolean() }),
5150
middleware: func(),
5251
open: union([boolean(), type({})]),
53-
port: union([port, promise]),
52+
port: union([max(integer(), 65535), promise]),
5453
progress: union([boolean(), literal('minimal')]),
5554
ramdisk: union([boolean(), type({})]),
5655
secure: never(),

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
"p-defer": "^3.0.0",
5858
"rimraf": "^3.0.2",
5959
"strip-ansi": "^6.0.0",
60-
"superstruct": "^0.10.12",
60+
"superstruct": "^0.11.1",
6161
"webpack-plugin-ramdisk": "^0.1.2",
6262
"ws": "^7.1.0"
6363
},

test/snapshots/validate.test.js.md

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,41 +8,45 @@ Generated by [AVA](https://ava.li).
88

99
> Snapshot 1
1010
11-
TypeError (StructError) {
11+
StructError {
1212
branch: [
1313
{
1414
foo: 'bar',
1515
},
1616
'bar',
1717
],
18-
failures: GeneratorFunction failures {},
18+
failures: Function {},
19+
key: 'foo',
1920
path: [
2021
'foo',
2122
],
23+
refinement: undefined,
2224
type: 'never',
2325
value: 'bar',
24-
message: 'Expected a value of type `never` for `foo` but received `"bar"`.',
26+
message: 'At path: foo -- Expected a value of type `never` for `foo`, but received: `"bar"`',
2527
}
2628

2729
## promise
2830

2931
> Snapshot 1
3032
31-
TypeError (StructError) {
33+
StructError {
3234
branch: [
3335
{
3436
host: 0,
3537
port: '0',
3638
},
3739
0,
3840
],
39-
failures: GeneratorFunction failures {},
41+
failures: Function {},
42+
key: 'host',
4043
path: [
4144
'host',
4245
],
43-
type: 'promise-like | string',
46+
refinement: undefined,
47+
type: 'union',
4448
value: 0,
45-
message: 'Expected a value of type `promise-like | string` for `host` but received `0`.',
49+
message: 'At path: host -- Expected the value to satisfy a union of `any | string`, but received: 0',
4650
}
4751

4852
> Snapshot 2
@@ -73,18 +77,20 @@ Generated by [AVA](https://ava.li).
7377

7478
> Snapshot 1
7579
76-
TypeError (StructError) {
80+
StructError {
7781
branch: [
7882
{
7983
batman: 'nanananana',
8084
},
8185
'nanananana',
8286
],
83-
failures: GeneratorFunction failures {},
87+
failures: Function {},
88+
key: 'batman',
8489
path: [
8590
'batman',
8691
],
92+
refinement: undefined,
8793
type: 'never',
8894
value: 'nanananana',
89-
message: 'Expected a value of type `never` for `batman` but received `"nanananana"`.',
95+
message: 'At path: batman -- Expected a value of type `never` for `batman`, but received: `"nanananana"`',
9096
}

test/snapshots/validate.test.js.snap

56 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)