Skip to content

Commit ee5e1aa

Browse files
committed
deps: @npmcli/[email protected]
1 parent 5df69b4 commit ee5e1aa

File tree

6 files changed

+61
-18
lines changed

6 files changed

+61
-18
lines changed

node_modules/@npmcli/redact/lib/deep-map.js

+3-11
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,12 @@
1-
function filterError (input) {
2-
return {
3-
errorType: input.name,
4-
message: input.message,
5-
stack: input.stack,
6-
...(input.code ? { code: input.code } : {}),
7-
...(input.statusCode ? { statusCode: input.statusCode } : {}),
8-
}
9-
}
1+
const { serializeError } = require('./error')
102

113
const deepMap = (input, handler = v => v, path = ['$'], seen = new Set([input])) => {
124
// this is in an effort to maintain bole's error logging behavior
135
if (path.join('.') === '$' && input instanceof Error) {
14-
return deepMap({ err: filterError(input) }, handler, path, seen)
6+
return deepMap({ err: serializeError(input) }, handler, path, seen)
157
}
168
if (input instanceof Error) {
17-
return deepMap(filterError(input), handler, path, seen)
9+
return deepMap(serializeError(input), handler, path, seen)
1810
}
1911
if (input instanceof Buffer) {
2012
return `[unable to log instanceof buffer]`
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/** takes an error object and serializes it to a plan object */
2+
function serializeError (input) {
3+
if (!(input instanceof Error)) {
4+
if (typeof input === 'string') {
5+
const error = new Error(`attempted to serialize a non-error, string String, "${input}"`)
6+
return serializeError(error)
7+
}
8+
const error = new Error(`attempted to serialize a non-error, ${typeof input} ${input?.constructor?.name}`)
9+
return serializeError(error)
10+
}
11+
// different error objects store status code differently
12+
// AxiosError uses `status`, other services use `statusCode`
13+
const statusCode = input.statusCode ?? input.status
14+
// CAUTION: what we serialize here gets add to the size of logs
15+
return {
16+
errorType: input.errorType ?? input.constructor.name,
17+
...(input.message ? { message: input.message } : {}),
18+
...(input.stack ? { stack: input.stack } : {}),
19+
// think of this as error code
20+
...(input.code ? { code: input.code } : {}),
21+
// think of this as http status code
22+
...(statusCode ? { statusCode } : {}),
23+
}
24+
}
25+
26+
module.exports = {
27+
serializeError,
28+
}

node_modules/@npmcli/redact/lib/server.js

+24-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ const {
1414
redactMatchers,
1515
} = require('./utils')
1616

17+
const { serializeError } = require('./error')
18+
1719
const { deepMap } = require('./deep-map')
1820

1921
const _redact = redactMatchers(
@@ -31,4 +33,25 @@ const _redact = redactMatchers(
3133

3234
const redact = (input) => deepMap(input, (value, path) => _redact(value, { path }))
3335

34-
module.exports = { redact }
36+
/** takes an error returns new error keeping some custom properties */
37+
function redactError (input) {
38+
const { message, ...data } = serializeError(input)
39+
const output = new Error(redact(message))
40+
return Object.assign(output, redact(data))
41+
}
42+
43+
/** runs a function within try / catch and throws error wrapped in redactError */
44+
function redactThrow (func) {
45+
if (typeof func !== 'function') {
46+
throw new Error('redactThrow expects a function')
47+
}
48+
return async (...args) => {
49+
try {
50+
return await func(...args)
51+
} catch (error) {
52+
throw redactError(error)
53+
}
54+
}
55+
}
56+
57+
module.exports = { redact, redactError, redactThrow }

node_modules/@npmcli/redact/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@npmcli/redact",
3-
"version": "3.0.0",
3+
"version": "3.1.1",
44
"description": "Redact sensitive npm information from output",
55
"main": "lib/index.js",
66
"exports": {

package-lock.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
"@npmcli/map-workspaces": "^4.0.2",
9292
"@npmcli/package-json": "^6.1.1",
9393
"@npmcli/promise-spawn": "^8.0.2",
94-
"@npmcli/redact": "^3.0.0",
94+
"@npmcli/redact": "^3.1.1",
9595
"@npmcli/run-script": "^9.0.1",
9696
"@sigstore/tuf": "^3.0.0",
9797
"abbrev": "^3.0.0",
@@ -3716,9 +3716,9 @@
37163716
}
37173717
},
37183718
"node_modules/@npmcli/redact": {
3719-
"version": "3.0.0",
3720-
"resolved": "https://registry.npmjs.org/@npmcli/redact/-/redact-3.0.0.tgz",
3721-
"integrity": "sha512-/1uFzjVcfzqrgCeGW7+SZ4hv0qLWmKXVzFahZGJ6QuJBj6Myt9s17+JL86i76NV9YSnJRcGXJYQbAU0rn1YTCQ==",
3719+
"version": "3.1.1",
3720+
"resolved": "https://registry.npmjs.org/@npmcli/redact/-/redact-3.1.1.tgz",
3721+
"integrity": "sha512-3Hc2KGIkrvJWJqTbvueXzBeZlmvoOxc2jyX00yzr3+sNFquJg0N8hH4SAPLPVrkWIRQICVpVgjrss971awXVnA==",
37223722
"inBundle": true,
37233723
"license": "ISC",
37243724
"engines": {

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
"@npmcli/map-workspaces": "^4.0.2",
5959
"@npmcli/package-json": "^6.1.1",
6060
"@npmcli/promise-spawn": "^8.0.2",
61-
"@npmcli/redact": "^3.0.0",
61+
"@npmcli/redact": "^3.1.1",
6262
"@npmcli/run-script": "^9.0.1",
6363
"@sigstore/tuf": "^3.0.0",
6464
"abbrev": "^3.0.0",

0 commit comments

Comments
 (0)