@antora/ui-loader 3.2.0-alpha.3 → 3.2.0-alpha.4

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.
Files changed (2) hide show
  1. package/lib/load-ui.js +14 -11
  2. package/package.json +1 -1
package/lib/load-ui.js CHANGED
@@ -8,6 +8,7 @@ const { promises: fsp } = require('fs')
8
8
  const { concat: get } = require('simple-get')
9
9
  const getCacheDir = require('cache-directory')
10
10
  const globStream = require('glob-stream')
11
+ const { inspect } = require('util')
11
12
  const ospath = require('path')
12
13
  const { posix: path } = ospath
13
14
  const picomatch = require('picomatch')
@@ -111,12 +112,10 @@ async function loadUi (playbook) {
111
112
  .on('error', reject)
112
113
  .pipe(collectFiles(resolve))
113
114
  ).catch((err) => {
114
- const errWrapper = new Error(
115
+ const msg =
115
116
  `Failed to read UI ${bundleFile.isDirectory() ? 'directory' : 'bundle'}: ` +
116
- (bundleUrl === bundleFile.path ? bundleUrl : `${bundleFile.path} (resolved from url: ${bundleUrl})`)
117
- )
118
- errWrapper.stack += `\nCaused by: ${err.stack || 'unknown'}`
119
- throw errWrapper
117
+ (bundleUrl === bundleFile.path ? bundleUrl : `${bundleFile.path} (resolved from url: ${bundleUrl})`)
118
+ throw transformError(err, msg)
120
119
  })
121
120
  ),
122
121
  srcSupplementalFiles(supplementalFilesSpec, startDir),
@@ -193,11 +192,11 @@ function downloadBundle (url, to, agent) {
193
192
  )
194
193
  })
195
194
  }).catch((err) => {
196
- const errWrapper = new Error(`${err.summary || 'Failed to download UI bundle'}: ${url}`)
195
+ const errWrapper = transformError(err, `${err.summary || 'Failed to download UI bundle'}: ${url}`)
197
196
  if (err.code === 'ECONNRESET' || (err.message || '').toLowerCase() === 'request timed out') {
198
- errWrapper.recoverable = true
197
+ Object.defineProperty(errWrapper, 'recoverable', { value: true })
199
198
  }
200
- throw Object.assign(errWrapper, { stack: `${errWrapper.stack}\nCaused by: ${err.stack || 'unknown'}` })
199
+ throw errWrapper
201
200
  })
202
201
  }
203
202
 
@@ -291,9 +290,7 @@ function srcSupplementalFiles (filesSpec, startDir) {
291
290
  if (err.code === 'ENOENT' && err.path === cwd) {
292
291
  throw new Error(`Specified ui.supplemental_files directory does not exist: ${dir}`)
293
292
  } else {
294
- const errWrapper = new Error(`Failed to read ui.supplemental_files ${cwd ? `directory: ${dir}` : 'entry'}`)
295
- errWrapper.stack += `\nCaused by: ${err.stack || 'unknown'}`
296
- throw errWrapper
293
+ throw transformError(err, `Failed to read ui.supplemental_files ${cwd ? `directory: ${dir}` : 'entry'}`)
297
294
  }
298
295
  })
299
296
  }
@@ -407,4 +404,10 @@ function symlinkAwareStat (path_) {
407
404
  })
408
405
  }
409
406
 
407
+ function transformError (err, msg) {
408
+ const errWrapper = new Error(msg)
409
+ errWrapper.stack += `\nCaused by: ${err.stack ? inspect(err).replace(/^Error \[(.+)\](?=: )/, '$1') : err}`
410
+ return errWrapper
411
+ }
412
+
410
413
  module.exports = loadUi
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antora/ui-loader",
3
- "version": "3.2.0-alpha.3",
3
+ "version": "3.2.0-alpha.4",
4
4
  "description": "Downloads a UI bundle, if necessary, and loads the files into a UI catalog for use in an Antora documentation pipeline.",
5
5
  "license": "MPL-2.0",
6
6
  "author": "OpenDevise Inc. (https://opendevise.com)",