Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes15kdownloads
audit-error.js41 linesDownload Raw Back to utils
1const { log, output } = require('proc-log')
2const { redactLog: replaceInfo } = require('@npmcli/redact')
3
4// Print an error or just nothing if the audit report has an error.
5// This is called by the audit command, and by the reify-output util prints a JSON version of the error if it's --json.
6// Returns 'true' if there was an error, false otherwise.
7
8const auditError = (npm, report) => {
9  if (!report?.error) {
10    return false
11  }
12
13  if (npm.command !== 'audit') {
14    return true
15  }
16
17  const { error } = report
18
19  // ok, we care about it, then
20  log.warn('audit', error.message)
21  const { body: errBody } = error
22  const body = Buffer.isBuffer(errBody) ? errBody.toString() : errBody
23  if (npm.flatOptions.json) {
24    output.buffer({
25      message: error.message,
26      method: error.method,
27      uri: replaceInfo(error.uri),
28      headers: error.headers,
29      statusCode: error.statusCode,
30      body,
31    })
32  } else {
33    output.standard(body)
34  }
35
36  // XXX we should throw a real error here
37  throw 'audit endpoint returned an error'
38}
39
40module.exports = auditError
41 
codekingpro/portable-devtools · Team Ai