style: use unknown in try/catch (#7709)

This commit is contained in:
Zoltan Kochan authored and GitHub committed 2024-03-06 01:47:04 +01:00
1 parent 9e6bbfb778
commit 0564745b1d
41 files changed
+201 -119

No files matched your search

+5 -2
View File
@@ -1,4 +1,6 @@
/* eslint-disable no-await-in-loop */
import util from 'util'
import assert from 'assert'
import { PnpmError } from '@pnpm/error'
import { globalInfo, logger } from '@pnpm/logger'
import { removeBin } from '@pnpm/remove-bins'
@@ -53,8 +55,9 @@ async function removeNodeVersion (opts: NvmNodeCommandOptions, version: string):
removeBin(npmPath),
removeBin(npxPath),
])
} catch (err: any) { // eslint-disable-line
if (err.code !== 'ENOENT') return err
} catch (err: unknown) {
assert(util.types.isNativeError(err))
if (!('code' in err && err.code === 'ENOENT')) return err
}
}
+4 -3
View File
@@ -1,4 +1,5 @@
import { promises as fs } from 'fs'
import util from 'util'
import gfs from 'graceful-fs'
import path from 'path'
import { PnpmError } from '@pnpm/error'
@@ -23,8 +24,8 @@ export async function envUse (opts: NvmNodeCommandOptions, params: string[]) {
await symlinkDir(nodeDir, path.join(opts.pnpmHomeDir, CURRENT_NODE_DIRNAME))
try {
gfs.unlinkSync(dest)
} catch (err: any) { // eslint-disable-line
if (err.code !== 'ENOENT') throw err
} catch (err: unknown) {
if (!(util.types.isNativeError(err) && 'code' in err && err.code === 'ENOENT')) throw err
}
await symlinkOrHardLink(src, dest)
try {
@@ -42,7 +43,7 @@ export async function envUse (opts: NvmNodeCommandOptions, params: string[]) {
const cmdShimOpts = { createPwshFile: false }
await cmdShim(path.join(npmBinDir, 'npm-cli.js'), path.join(opts.bin, 'npm'), cmdShimOpts)
await cmdShim(path.join(npmBinDir, 'npx-cli.js'), path.join(opts.bin, 'npx'), cmdShimOpts)
} catch (err: any) { // eslint-disable-line
} catch {
// ignore
}
return `Node.js ${nodeVersion as string} was activated
+3 -2
View File
@@ -1,5 +1,6 @@
import fs from 'fs'
import path from 'path'
import util from 'util'
import { type Config } from '@pnpm/config'
import { createFetchFromRegistry, type FetchFromRegistry } from '@pnpm/fetch'
import { globalInfo } from '@pnpm/logger'
@@ -92,8 +93,8 @@ export async function getNodeDir (fetch: FetchFromRegistry, opts: NvmNodeCommand
async function readNodeVersionsManifest (nodesDir: string): Promise<{ default?: string }> {
try {
return await loadJsonFile<{ default?: string }>(path.join(nodesDir, 'versions.json'))
} catch (err: any) { // eslint-disable-line
if (err.code === 'ENOENT') {
} catch (err: unknown) {
if (util.types.isNativeError(err) && 'code' in err && err.code === 'ENOENT') {
return {}
}
throw err