@netflix/nerror 1.0.0 → 1.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,29 @@
1
+ <a name="1.1.3"></a>
2
+ ### 1.1.3 (2019-11-27)
3
+
4
+
5
+ #### Bug Fixes
6
+
7
+ * **nerror:** don't call extsprintf if single string passed to VError constructor (#11) ([89b2088b](https://github.com/Netflix/nerror/commit/89b2088b))
8
+
9
+
10
+ <a name="1.1.2"></a>
11
+ ### 1.1.2 (2019-07-26)
12
+
13
+
14
+ <a name="1.1.1"></a>
15
+ ### 1.1.1 (2019-07-09)
16
+
17
+
18
+ <a name="1.1.0"></a>
19
+ ## 1.1.0 (2019-05-06)
20
+
21
+
22
+ #### Features
23
+
24
+ * **errorForEach:** make it MultiError support more general (#2) ([96cc8769](https://github.com/Netflix/nerror/commit/96cc8769))
25
+
26
+
1
27
  <a name="1.0.0"></a>
2
28
  ## 1.0.0 (2019-05-02)
3
29
 
package/README.md CHANGED
@@ -60,7 +60,7 @@ JavaScript Error class, with the addition of printf-style messages:
60
60
 
61
61
  ```javascript
62
62
  const { VError } = require('@netflix/nerror');
63
- const err = new NError('missing file: "%s"', '/etc/passwd');
63
+ const err = new VError('missing file: "%s"', '/etc/passwd');
64
64
  console.log(err.message);
65
65
  ```
66
66
 
package/lib/index.d.ts ADDED
@@ -0,0 +1,67 @@
1
+ export class VError extends Error {
2
+ static VError: typeof VError;
3
+
4
+ static cause(err: Error): Error | null;
5
+ static info(err: Error): VError.Info;
6
+ static fullStack(err: Error): string;
7
+ static findCauseByName(err: Error, name: string): Error | null;
8
+ static hasCauseWithName(err: Error, name: string): boolean;
9
+ static errorFromList<T extends Error>(
10
+ errors: T[]
11
+ ): null | T | VError.MultiError;
12
+ static errorForEach(err: Error, func: (err: Error) => void): void;
13
+
14
+ cause(): Error | undefined;
15
+ constructor(
16
+ options: VError.Options | Error,
17
+ message: string,
18
+ ...params: any[]
19
+ );
20
+ constructor(message?: string, ...params: any[]);
21
+ }
22
+
23
+ export namespace VError {
24
+ interface Info {
25
+ [key: string]: any;
26
+ }
27
+
28
+ interface Options {
29
+ cause?: Error | null;
30
+ name?: string;
31
+ strict?: boolean;
32
+ constructorOpt?(...args: any[]): void;
33
+ info?: Info;
34
+ }
35
+
36
+ /*
37
+ * SError is like VError, but stricter about types. You cannot pass "null" or
38
+ * "undefined" as string arguments to the formatter. Since SError is only a
39
+ * different function, not really a different class, we don't set
40
+ * SError.prototype.name.
41
+ */
42
+ class SError extends VError {}
43
+
44
+ /*
45
+ * PError is like VError, but the message is not run through printf-style
46
+ * templating.
47
+ */
48
+ class PError extends VError {}
49
+
50
+ /*
51
+ * Represents a collection of errors for the purpose of consumers that generally
52
+ * only deal with one error. Callers can extract the individual errors
53
+ * contained in this object, but may also just treat it as a normal single
54
+ * error, in which case a summary message will be printed.
55
+ */
56
+ class MultiError extends VError {
57
+ constructor(errors: Error[]);
58
+ errors(): Error[];
59
+ }
60
+
61
+ /*
62
+ * Like JavaScript's built-in Error class, but supports a "cause" argument which
63
+ * is wrapped, not "folded in" as with VError. Accepts a printf-style message.
64
+ * The cause argument can be null.
65
+ */
66
+ class WError extends VError {}
67
+ }
package/lib/verror.js CHANGED
@@ -134,7 +134,10 @@ function parseConstructorArguments(args) {
134
134
 
135
135
  if (sprintf_args.length === 0) {
136
136
  shortmessage = '';
137
- } else if (options.skipPrintf) {
137
+ } else if (
138
+ options.skipPrintf ||
139
+ (sprintf_args.length === 1 && typeof sprintf_args[0] === 'string')
140
+ ) {
138
141
  assert.equal(
139
142
  sprintf_args.length,
140
143
  1,
@@ -597,7 +600,7 @@ VError.errorForEach = function errorForEach(err, func) {
597
600
  VError._assertError(err);
598
601
  assert.func(func, 'func');
599
602
 
600
- if (err instanceof MultiError) {
603
+ if (err.name === 'MultiError') {
601
604
  err.errors().forEach(function iterError(e) {
602
605
  func(e);
603
606
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netflix/nerror",
3
- "version": "1.0.0",
3
+ "version": "1.1.3",
4
4
  "main": "lib/index.js",
5
5
  "description": "Rich errors",
6
6
  "homepage": "https://github.com/Netflix/nerror",
@@ -10,8 +10,10 @@
10
10
  },
11
11
  "license": "MIT",
12
12
  "files": [
13
- "lib"
13
+ "lib",
14
+ "lib/index.d.ts"
14
15
  ],
16
+ "types": "lib/index.d.ts",
15
17
  "keywords": [
16
18
  "nerror",
17
19
  "error",
@@ -29,14 +31,18 @@
29
31
  "mocha": "^5.2.0",
30
32
  "nyc": "^12.0.2",
31
33
  "prettier": "^1.13.5",
34
+ "tsd": "^0.7.3",
32
35
  "unleash": "^2.0.1"
33
36
  },
34
37
  "dependencies": {
35
38
  "assert-plus": "^1.0.0",
36
39
  "extsprintf": "^1.4.0",
37
- "lodash": "^4.17.11"
40
+ "lodash": "^4.17.15"
38
41
  },
39
42
  "scripts": {
40
- "test": "make prepush"
43
+ "test": "make prepush & tsd"
44
+ },
45
+ "tsd": {
46
+ "directory": "test"
41
47
  }
42
48
  }