diff --git a/workspaces/arborist/lib/shrinkwrap.js b/workspaces/arborist/lib/shrinkwrap.js index b45fea0ac6111..bb6971f7ad57a 100644 --- a/workspaces/arborist/lib/shrinkwrap.js +++ b/workspaces/arborist/lib/shrinkwrap.js @@ -476,8 +476,13 @@ class Shrinkwrap { // all good! hidden lockfile is the newest thing in here. return data }).catch(er => { - const rel = relpath(this.path, this.filename) - this.log.verbose('shrinkwrap', `failed to load ${rel}`, er) + /* istanbul ignore else */ + if (typeof this.filename === 'string') { + const rel = relpath(this.path, this.filename) + this.log.verbose('shrinkwrap', `failed to load ${rel}`, er) + } else { + this.log.verbose('shrinkwrap', `failed to load ${this.path}`, er) + } this.loadingError = er this.loadedFromDisk = false this.ancientLockfile = false diff --git a/workspaces/arborist/test/shrinkwrap.js b/workspaces/arborist/test/shrinkwrap.js index f752c724a35e7..d47266d30e1c1 100644 --- a/workspaces/arborist/test/shrinkwrap.js +++ b/workspaces/arborist/test/shrinkwrap.js @@ -1597,4 +1597,19 @@ t.test('setting lockfileVersion from the file contents', async t => { }) t.equal(Shrinkwrap.defaultLockfileVersion, 2, 'default is 2') + + t.test('load should return error correctly when it cant access folder', + { skip: process.platform === 'win32' ? 'skip chmod in windows' : false }, + async t => { + const dir = t.testdir({}) + try { + fs.chmodSync(dir, '000') + const res = await Shrinkwrap.load({ path: dir }) + t.ok(res.loadingError, 'loading error should exist') + t.strictSame(res.loadingError.errno, -13) + t.strictSame(res.loadingError.code, 'EACCES') + } finally { + fs.chmodSync(dir, '666') + } + }) })