Skip to content

Commit

Permalink
Use optional catch bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanZim committed Feb 3, 2020
1 parent 3045387 commit 54b70a7
Show file tree
Hide file tree
Showing 10 changed files with 16 additions and 17 deletions.
4 changes: 2 additions & 2 deletions lib/copy/__tests__/copy-permissions.test.js
Expand Up @@ -32,13 +32,13 @@ describe('copy', () => {

try {
gidWheel = process.getgid() // userid.gid('wheel')
} catch (err) {
} catch {
gidWheel = process.getgid()
}

try {
gidStaff = process.getgid() // userid.gid('staff')
} catch (err) {
} catch {
gidStaff = process.getgid()
}

Expand Down
2 changes: 1 addition & 1 deletion lib/empty/index.js
Expand Up @@ -30,7 +30,7 @@ function emptyDirSync (dir) {
let items
try {
items = fs.readdirSync(dir)
} catch (err) {
} catch {
return mkdir.mkdirsSync(dir)
}

Expand Down
2 changes: 1 addition & 1 deletion lib/ensure/file.js
Expand Up @@ -44,7 +44,7 @@ function createFileSync (file) {
let stats
try {
stats = fs.statSync(file)
} catch (e) {}
} catch {}
if (stats && stats.isFile()) return

const dir = path.dirname(file)
Expand Down
2 changes: 1 addition & 1 deletion lib/ensure/symlink-type.js
Expand Up @@ -19,7 +19,7 @@ function symlinkTypeSync (srcpath, type) {
if (type) return type
try {
stats = fs.lstatSync(srcpath)
} catch (e) {
} catch {
return 'file'
}
return (stats && stats.isDirectory()) ? 'dir' : 'file'
Expand Down
3 changes: 1 addition & 2 deletions lib/mkdirs/__tests__/issue-209.test.js
Expand Up @@ -30,8 +30,7 @@ describe('mkdirp: issue-209, win32, when bad path, should return a cleaner error
try {
const file = 'c:\\tmp\foo:moo'
fse.mkdirpSync(file)
} catch (err) {
// console.error(err)
} catch {
didErr = true
}
assert(didErr)
Expand Down
12 changes: 6 additions & 6 deletions lib/mkdirs/mkdirs-sync.js
Expand Up @@ -28,9 +28,9 @@ function mkdirsSync (p, opts, made) {
try {
xfs.mkdirSync(p, mode)
made = made || p
} catch (err0) {
if (err0.code === 'ENOENT') {
if (path.dirname(p) === p) throw err0
} catch (err) {
if (err.code === 'ENOENT') {
if (path.dirname(p) === p) throw err
made = mkdirsSync(path.dirname(p), opts, made)
mkdirsSync(p, opts, made)
} else {
Expand All @@ -39,10 +39,10 @@ function mkdirsSync (p, opts, made) {
let stat
try {
stat = xfs.statSync(p)
} catch (err1) {
throw err0
} catch {
throw err
}
if (!stat.isDirectory()) throw err0
if (!stat.isDirectory()) throw err
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/move-sync/__tests__/move-sync.test.js
Expand Up @@ -281,7 +281,7 @@ describe('moveSync()', () => {
// make sure we have permission on device
try {
fs.writeFileSync(path.join(differentDevice, 'file'), 'hi')
} catch (err) {
} catch {
console.log("Can't write to device. Skipping moveSync test.")
__skipTests = true
}
Expand Down
2 changes: 1 addition & 1 deletion lib/move/__tests__/move.test.js
Expand Up @@ -324,7 +324,7 @@ describe('+ move()', () => {
// make sure we have permission on device
try {
fs.writeFileSync(path.join(differentDevice, 'file'), 'hi')
} catch (err) {
} catch {
console.log("Can't write to device. Skipping move test.")
__skipTests = true
}
Expand Down
2 changes: 1 addition & 1 deletion lib/remove/rimraf.js
Expand Up @@ -302,7 +302,7 @@ function rmkidsSync (p, options) {
try {
const ret = options.rmdirSync(p, options)
return ret
} catch (er) { }
} catch {}
} while (Date.now() - startTime < 500) // give up after 500ms
} else {
const ret = options.rmdirSync(p, options)
Expand Down
2 changes: 1 addition & 1 deletion lib/util/buffer.js
Expand Up @@ -4,7 +4,7 @@ module.exports = function (size) {
if (typeof Buffer.allocUnsafe === 'function') {
try {
return Buffer.allocUnsafe(size)
} catch (e) {
} catch {
return new Buffer(size)
}
}
Expand Down

0 comments on commit 54b70a7

Please sign in to comment.