loggable-error 1.0.1 → 1.0.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.
@@ -0,0 +1,31 @@
1
+ name: Unit tests in CI
2
+
3
+ permissions:
4
+ contents: read
5
+ pull-requests: write
6
+
7
+ on:
8
+ push:
9
+ branches: [ "main" ]
10
+ pull_request:
11
+ branches: [ "main" ]
12
+
13
+ jobs:
14
+ build:
15
+
16
+ runs-on: ubuntu-latest
17
+
18
+ strategy:
19
+ matrix:
20
+ node-version: [20.x, 22.x, 24.x]
21
+
22
+ steps:
23
+ - uses: actions/checkout@v5
24
+ - name: Use Node.js ${{ matrix.node-version }}
25
+ uses: actions/setup-node@v6
26
+ with:
27
+ node-version: ${{ matrix.node-version }}
28
+ cache: 'npm'
29
+ - run: npm ci
30
+ - run: npm run build --if-present
31
+ - run: npm test
@@ -0,0 +1,25 @@
1
+ name: NPM Publish
2
+
3
+ on:
4
+ release:
5
+ types: [published]
6
+
7
+ jobs:
8
+ npm-publish:
9
+ runs-on: ubuntu-latest
10
+ permissions:
11
+ contents: read
12
+ id-token: write
13
+ steps:
14
+ - uses: actions/checkout@v5
15
+ # Setup .npmrc file to publish to npm
16
+ - uses: actions/setup-node@v6
17
+ with:
18
+ node-version: 22.x
19
+ registry-url: 'https://registry.npmjs.org'
20
+ # Ensure npm 11.5.1 or later is installed
21
+ - run: npm install -g npm@latest
22
+ - run: npm ci
23
+ - run: npm run build --if-present
24
+ - run: npm publish --provenance --access public
25
+
package/README.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # loggable-error
2
2
 
3
+ [
4
+ ![ci status](https://github.com/EvanK/npm-loggable-error/actions/workflows/ci.yml/badge.svg)
5
+ ](https://github.com/EvanK/loggable-error/actions/workflows/ci.yml)
6
+ [
7
+ ![node.js supported as of v20](https://img.shields.io/badge/Node.js-v20-yellow)
8
+ ](https://nodejs.org/docs/latest-v20.x/api/)
9
+
10
+ [
11
+ ![npm](https://nodei.co/npm/npm-loggable-error.png)
12
+ ](https://www.npmjs.com/package/npm-loggable-error)
13
+
3
14
  In those times when you need to log an error to somewhere other than standard output, this simple module stringifies Error objects in a format akin to `console.log`:
4
15
 
5
16
  ```js
@@ -30,3 +41,26 @@ Error: testing one two three
30
41
  at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
31
42
  at node:internal/main/run_main_module:17:47
32
43
  ```
44
+
45
+ ## Stringification Options
46
+
47
+ Our exported function accepts a second `options` argument, in case you want to control whether stack traces are displayed or the amount of starting indentation:
48
+
49
+ ```js
50
+ stringify(e, { stack: false });
51
+ // => 'Error: testing one two three'
52
+
53
+ stringify(e, { depth: 8 });
54
+ /* =>
55
+ ' Error: testing one two three\n' +
56
+ ' at Object.<anonymous> (/home/jdoe/test.js:7:9)\n' +
57
+ ' at Module._compile (node:internal/modules/cjs/loader:1546:14)\n' +
58
+ ' at Module._extensions..js (node:internal/modules/cjs/loader:1691:10)\n' +
59
+ ' at Module.load (node:internal/modules/cjs/loader:1317:32)\n' +
60
+ ' at Module._load (node:internal/modules/cjs/loader:1127:12)\n' +
61
+ ' at TracingChannel.traceSync (node:diagnostics_channel:315:14)\n' +
62
+ ' at wrapModuleLoad (node:internal/modules/cjs/loader:217:24)\n' +
63
+ ' at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:166:5)\n' +
64
+ ' at node:internal/main/run_main_module:30:49'
65
+ */
66
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "loggable-error",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "Stringifies errors into a format similar to console.log",
5
5
  "main": "./src/main.cjs",
6
6
  "exports": {
package/src/main.cjs CHANGED
@@ -15,7 +15,7 @@ function stringify(err, options = {}) {
15
15
  const depth = options.hasOwnProperty('depth') ? parseInt(options.depth, 10) : 0;
16
16
  const stack = options.hasOwnProperty('stack') ? (!!options.stack) : true;
17
17
 
18
- let collapsed = '';
18
+ let collapsed = ' '.repeat(depth);
19
19
  if (err instanceof Error) {
20
20
  let body;
21
21
  if (stack) {
@@ -52,7 +52,7 @@ function stringify(err, options = {}) {
52
52
 
53
53
  // if another error object, stringify it too
54
54
  if (err[property] instanceof Error) {
55
- collapsed += stringify(err[property], { depth: depth + 2, stack });
55
+ collapsed += stringify(err[property], { depth: depth + 2, stack }).trimStart();
56
56
  }
57
57
  // otherwise stringify as JSON
58
58
  else {