Skip to content

Commit

Permalink
refactor: Fix @typescript-eslint/no-unused-vars warnings (#2713)
Browse files Browse the repository at this point in the history
Removed some unused variables. Eslint 's
`typescript-eslint/no-unused-vars` rule would warn about these when we
upgrade to eslint v9.

All the modifications are about `try ... catch` blocks: we catch an
error, but ignore the throw error object.
  • Loading branch information
teogeb committed Aug 12, 2024
1 parent d19522b commit ccec856
Show file tree
Hide file tree
Showing 25 changed files with 35 additions and 35 deletions.
2 changes: 1 addition & 1 deletion packages/autocertifier-server/src/DnsServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export class DnsServer {
let subdomainRecord: Subdomain | undefined
try {
subdomainRecord = await this.db.getSubdomain(subdomain)
} catch (e) {
} catch {
logger.error('handleAQuery exception')
}

Expand Down
2 changes: 1 addition & 1 deletion packages/cdn-location/src/getLocalRegion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const getLocalAirportCode: () => Promise<string | undefined> = async () =
let airportCode: string
try {
airportCode = await fetchAirportCodeFromCdn()
} catch (error) {
} catch {
return undefined
}
return airportCode
Expand Down
2 changes: 1 addition & 1 deletion packages/cli-tools/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const tryReadConfigFile = (fileName: string): Config | undefined | never => {
let content
try {
content = readFileSync(fileName, 'utf8')
} catch (e: any) {
} catch {
return undefined
}
const json = JSON.parse(content)
Expand Down
2 changes: 1 addition & 1 deletion packages/dht/src/connection/connectivityChecker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const connectAsync = async ({ url, allowSelfSignedCertificate, timeoutMs
() => { socket.connect(url, allowSelfSignedCertificate) }],
socket, ['connected', 'error'],
timeoutMs)
} catch (e) {
} catch {
throw new Err.ConnectionFailed('WebSocket connection timed out')
}
if (result.winnerName === 'error') {
Expand Down
4 changes: 2 additions & 2 deletions packages/dht/src/connection/webrtc/NodeWebrtcConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export class NodeWebrtcConnection extends EventEmitter<Events> implements IConne
logger.trace(`Setting remote descriptor for peer: ${remoteNodeId}`)
this.connection.setRemoteDescription(description, type as DescriptionType)
this.remoteDescriptionSet = true
} catch (err) {
} catch {
logger.debug(`Failed to set remote descriptor for peer ${remoteNodeId}`)
}
} else {
Expand All @@ -121,7 +121,7 @@ export class NodeWebrtcConnection extends EventEmitter<Events> implements IConne
try {
logger.trace(`Setting remote candidate for peer: ${remoteNodeId}`)
this.connection.addRemoteCandidate(candidate, mid)
} catch (err) {
} catch {
logger.debug(`Failed to set remote candidate for peer ${remoteNodeId}`)
}
} else {
Expand Down
4 changes: 2 additions & 2 deletions packages/dht/src/dht/ExternalApiRpcRemote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class ExternalApiRpcRemote extends RpcRemote<ExternalApiRpcClient> {
try {
const data = await this.getClient().externalFetchData(request, options)
return data.entries
} catch (err) {
} catch {
return []
}
}
Expand All @@ -34,7 +34,7 @@ export class ExternalApiRpcRemote extends RpcRemote<ExternalApiRpcClient> {
try {
const response = await this.getClient().externalStoreData(request, options)
return response.storers
} catch (err) {
} catch {
return []
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/dht/src/dht/discovery/PeerDiscovery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ export class PeerDiscovery {
try {
await this.joinThroughEntryPoint(entryPoint, contactedPeers, { enabled: true, contactedPeers: distantJoinContactPeers })
logger.debug(`Rejoined DHT successfully ${this.options.serviceId}!`)
} catch (err) {
} catch {
logger.warn(`Rejoining DHT ${this.options.serviceId} failed`)
if (!this.isStopped()) {
// TODO should we catch possible promise rejection?
Expand Down
2 changes: 1 addition & 1 deletion packages/dht/src/dht/routing/Router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export class Router {
// TODO use options option or named constant?
await withTimeout(eventReceived, 10000)
logger.trace('raceEvents ended from routingSession: ' + session.sessionId)
} catch (e) {
} catch {
logger.trace('raceEvents timed out for routingSession ' + session.sessionId)
}
session.stop()
Expand Down
2 changes: 1 addition & 1 deletion packages/dht/test/benchmark/KademliaCorrectness.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ describe('Kademlia correctness', () => {
}
correctNeighbors++
}
} catch (e) {
} catch {
console.error('Node ' + getNodeIdFromPeerDescriptor(nodes[i].getLocalPeerDescriptor()) + ' had only '
+ kademliaNeighbors.length + ' kademlia neighbors')
}
Expand Down
2 changes: 1 addition & 1 deletion packages/dht/test/benchmark/RingCorrectness.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ describe('Ring correctness', () => {
}
correctNeighbors++
}
} catch (e) {
} catch {
console.error('Node ' + getNodeIdFromPeerDescriptor(nodes[i].getLocalPeerDescriptor()) + ' had only '
+ kademliaNeighbors.length + ' kademlia neighbors')
}
Expand Down
2 changes: 1 addition & 1 deletion packages/dht/test/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ export const waitForStableTopology = async (nodes: DhtNode[], maxConnectionCount
connectionManager.garbageCollectConnections(maxConnectionCount, MAX_IDLE_TIME)
try {
await waitForCondition(() => connectionManager.getConnections().length <= maxConnectionCount, waitTime)
} catch (err) {
} catch {
// the topology is very likely stable, but we can't be sure (maybe the node has more than maxConnectionCount
// locked connections and therefore it is ok to that garbage collector was not able to remove any of those
// connections
Expand Down
8 changes: 4 additions & 4 deletions packages/geoip-location/src/downloadGeoIpDatabase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const downloadNewDb = async (
} catch (e) {
try {
fs.rmSync(downloadFolder, { recursive: true })
} catch (e2) {
} catch {
// ignore error when removing the temporary folder
}
throw e
Expand All @@ -67,7 +67,7 @@ const downloadNewDb = async (
if (!isDbFileValid(dbFileInDownloadFolder, remoteHash)) {
try {
fs.rmSync(downloadFolder, { recursive: true })
} catch (e2) {
} catch {
// ignore error when removing the temporary folder
}
throw new Error('Downloaded database hash does not match the expected hash')
Expand All @@ -81,7 +81,7 @@ const downloadNewDb = async (
} finally {
try {
fs.rmSync(downloadFolder, { recursive: true })
} catch (e2) {
} catch {
// ignore error when removing the temporary folder
}
}
Expand Down Expand Up @@ -131,7 +131,7 @@ const isDbFileValid = async (dbFile: string, remoteHash: string): Promise<boolea
} else {
return true
}
} catch (e) {
} catch {
// if the local db does not exist, or some other exception occurres db is not considered valid
return false
}
Expand Down
2 changes: 1 addition & 1 deletion packages/geoip-location/test/helpers/TestServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export class TestServer extends EventEmitter<TestServerEvents> {
// save db and hash data to CACHE_PATH
try {
fs.mkdirSync(CACHE_PATH, { recursive: true })
} catch (e) {
} catch {
// ignore error when creating the cache folder
}
// ensure there is never an incomplete file in the fs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe('GeoIpLocator', () => {

try {
fs.unlinkSync(dbDir + '/' + DB_FILENAME)
} catch (e) {
} catch {
// ignore
}

Expand All @@ -49,7 +49,7 @@ describe('GeoIpLocator', () => {
// delete the db
try {
fs.unlinkSync(dbDir + '/' + DB_FILENAME)
} catch (e) {
} catch {
// ignore
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('downloadGeoIpDatabase', () => {
beforeEach(() => {
try {
fs.rmSync(path, { recursive: true })
} catch (e) {
} catch {
// ignore error when removing the test data
}
})
Expand Down
4 changes: 2 additions & 2 deletions packages/node/src/config/ConfigWizard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export async function start(): Promise<void> {
} else {
log(`> ${content}`)
}
} catch (e) {
} catch {
resume()

log('> x Failed to fetch node\'s balance')
Expand Down Expand Up @@ -162,7 +162,7 @@ export async function start(): Promise<void> {
}

log(`> *https://streamr.network/hub/network/operators/${operator}*`)
} catch (e) {
} catch {
resume()

log('> x Failed to fetch operator nodes')
Expand Down
4 changes: 2 additions & 2 deletions packages/proto-rpc/test/unit/ConversionWrappers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('ConversionWrappers', () => {
let errorCount = 0
try {
parseWrapper<RpcMessage>(() => RpcMessage.fromBinary(Buffer.from('adda')))
} catch (err) {
} catch {
errorCount += 1
}
expect(errorCount).toEqual(1)
Expand All @@ -41,7 +41,7 @@ describe('ConversionWrappers', () => {
)
)

} catch (err) {
} catch {
errorCount += 1
}
expect(errorCount).toEqual(1)
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/src/contracts/StreamRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ export class StreamRegistry {
// eslint-disable-next-line no-underscore-dangle
this.config._timeouts.ensStreamCreation.retryInterval
)
} catch (e) {
} catch {
throw new Error(`unable to create stream "${streamId}"`)
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/src/subscribe/Resends.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ const getHttpErrorTransform = (): (error: any) => Promise<StreamrClientError> =>
try {
const json = JSON.parse(body)
descriptionSnippet = `: ${json.error}`
} catch (err) {
} catch {
descriptionSnippet = ''
}
message = `Storage node fetch failed${descriptionSnippet}, httpStatus=${err.response.status}, url=${err.response.url}`
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/test/end-to-end/StreamRegistry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ describe('StreamRegistry', () => {
await until(async () => {
try {
return (await client.getStream(createdStream.id)).getMetadata().description === createdStream.getMetadata().description
} catch (err) {
} catch {
return false
}
}, 100000, 1000)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class PeerDescriptorStoreManager {
try {
const result = await this.options.fetchDataFromDht(this.options.key)
return parsePeerDescriptor(result)
} catch (err) {
} catch {
return []
}
}
Expand All @@ -65,7 +65,7 @@ export class PeerDescriptorStoreManager {
const dataToStore = Any.pack(localPeerDescriptor, PeerDescriptor)
try {
await this.options.storeDataToDht(this.options.key, dataToStore)
} catch (err) {
} catch {
logger.warn('Failed to store local node', { key: this.options.key })
}
}
Expand All @@ -79,7 +79,7 @@ export class PeerDescriptorStoreManager {
|| discovered.some((peerDescriptor) => areEqualPeerDescriptors(peerDescriptor, this.options.localPeerDescriptor))) {
await this.storeLocalNode()
}
} catch (err) {
} catch {
logger.debug('Failed to keep local node', { key: this.options.key })
}
}, this.options.storeInterval ?? 60000, false, this.abortController.signal)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const exponentialRunOff = async (
const delay = baseDelay * factor
try {
await task()
} catch (e: any) {
} catch {
logger.debug(`${description} failed, retrying in ${delay} ms`)
}
try { // Abort controller throws unexpected errors in destroy?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export class Inspector {
try {
await waitForEvent3<InspectSessionEvents>(session, 'done', this.inspectionTimeout)
success = true
} catch (err) {
} catch {
logger.trace('Inspect session timed out, removing')
} finally {
await this.closeInspectConnection(peerDescriptor, lockId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const retry = async <T>(task: () => Promise<T>, description: string, abor
try {
const result = await task()
return result
} catch (e: any) {
} catch {
logger.warn(`Failed ${description} (retrying after delay)`, {
delayInMs: delay
})
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/src/signingUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export function verifySignature(address: EthereumAddress, payload: Uint8Array, s
try {
const recoveredAddress = toEthereumAddress(recoverAddress(signature, payload))
return recoveredAddress === address
} catch (err) {
} catch {
return false
}
}

0 comments on commit ccec856

Please sign in to comment.