Skip to content

Commit

Permalink
Add _e objects for empty catch blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
nazarhussain committed Oct 9, 2024
1 parent dd79326 commit fba83fa
Show file tree
Hide file tree
Showing 38 changed files with 71 additions and 71 deletions.
2 changes: 1 addition & 1 deletion packages/api/src/utils/client/response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ export class ApiResponse<E extends Endpoint> extends Response {
} else {
return errBody;
}
} catch {
} catch (_e) {
return errBody || this.statusText;
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/utils/serdes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export function fromGraffitiHex(hex?: string): string | undefined {
}
try {
return new TextDecoder("utf8").decode(fromHex(hex));
} catch {
} catch (_e) {
// allow malformed graffiti hex string
return hex;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/api/test/utils/checkAgainstSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export function runTestCheckAgainstSpec<Es extends Record<string, Endpoint>>(

expect(reqSsz.body).toBeInstanceOf(Uint8Array);
expect(reqCodec.onlySupport).not.toBe(WireFormat.json);
} catch {
} catch (_e) {
throw Error("Must support ssz request body");
}
}
Expand Down Expand Up @@ -167,7 +167,7 @@ export function runTestCheckAgainstSpec<Es extends Record<string, Endpoint>>(

expect(sszBytes).toBeInstanceOf(Uint8Array);
expect(routeDef.resp.onlySupport).not.toBe(WireFormat.json);
} catch {
} catch (_e) {
throw Error("Must support ssz response body");
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/beacon-node/src/api/impl/beacon/state/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export function getStateValidatorIndex(
if (id.startsWith("0x")) {
try {
id = fromHex(id);
} catch {
} catch (_e) {
return {valid: false, code: 400, reason: "Invalid pubkey hex encoding"};
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion packages/beacon-node/src/api/rest/activeSockets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export class HttpActiveSocketsTracker {
await waitFor(() => this.sockets.size === 0, {
timeout: GRACEFUL_TERMINATION_TIMEOUT,
});
} catch {
} catch (_e) {
// Ignore timeout error
} finally {
for (const socket of this.sockets) {
Expand Down
2 changes: 1 addition & 1 deletion packages/beacon-node/src/api/rest/swaggerUI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ async function getAsset(name: string): Promise<Buffer | undefined> {
const url = await import("node:url");
const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
return await fs.readFile(path.join(__dirname, "../../../../../assets/", name));
} catch {
} catch (_e) {
return undefined;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ async function raceWithCutoff<T>(

try {
await Promise.race([availabilityPromise, cutoffTimeout]);
} catch {
} catch (_e) {
// throw unavailable so that the unknownblock/blobs can be triggered to pull the block
throw new BlockError(block, {code: BlockErrorCode.DATA_UNAVAILABLE});
}
Expand Down
2 changes: 1 addition & 1 deletion packages/beacon-node/src/chain/bls/multithread/poolSize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ try {
} else {
defaultPoolSize = (await import("node:os")).availableParallelism();
}
} catch {
} catch (_e) {
defaultPoolSize = 8;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/beacon-node/src/chain/bls/multithread/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ function verifyManySignatureSets(workReqArr: BlsWorkReq[]): BlsWorkResult {
// Re-verify all sigs
nonBatchableSets.push(...batchableChunk);
}
} catch {
} catch (_e) {
// TODO: Ignore this error expecting that the same error will happen when re-verifying the set individually
// It's not ideal but '@chainsafe/blst' may throw errors on some conditions
batchRetries++;
Expand Down
2 changes: 1 addition & 1 deletion packages/beacon-node/src/monitoring/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ export class MonitoringService {
}

return url;
} catch {
} catch (_e) {
throw new Error(`Monitoring endpoint must be a valid URL: ${endpoint}`);
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/beacon-node/src/network/gossip/topic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export function sszDeserialize<T extends GossipTopic>(topic: T, serializedData:
const sszType = getGossipSSZType(topic);
try {
return sszType.deserialize(serializedData) as SSZTypeOfGossipTopic<T>;
} catch {
} catch (_e) {
throw new GossipActionError(GossipAction.REJECT, {code: GossipErrorCode.INVALID_SERIALIZED_BYTES_ERROR_CODE});
}
}
Expand All @@ -130,7 +130,7 @@ export function sszDeserialize<T extends GossipTopic>(topic: T, serializedData:
export function sszDeserializeAttestation(fork: ForkName, serializedData: Uint8Array): Attestation {
try {
return sszTypesFor(fork).Attestation.deserialize(serializedData);
} catch {
} catch (_e) {
throw new GossipActionError(GossipAction.REJECT, {code: GossipErrorCode.INVALID_SERIALIZED_BYTES_ERROR_CODE});
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/beacon-node/src/network/peers/datastore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export class Eth2PeerDataStore extends BaseDatastore {
if (this._dirtyItems.size >= this._threshold) {
try {
await this._commitData();
} catch {}
} catch (_e) {}
}
}

Expand Down
8 changes: 4 additions & 4 deletions packages/beacon-node/src/network/peers/peerManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ export class PeerManager {
private async requestMetadata(peer: PeerId): Promise<void> {
try {
this.onMetadata(peer, await this.reqResp.sendMetadata(peer));
} catch {
} catch (_e) {
// TODO: Downvote peer here or in the reqResp layer
}
}
Expand All @@ -395,15 +395,15 @@ export class PeerManager {
// If peer replies a PING request also update lastReceivedMsg
const peerData = this.connectedPeers.get(peer.toString());
if (peerData) peerData.lastReceivedMsgUnixTsMs = Date.now();
} catch {
} catch (_e) {
// TODO: Downvote peer here or in the reqResp layer
}
}

private async requestStatus(peer: PeerId, localStatus: phase0.Status): Promise<void> {
try {
this.onStatus(peer, await this.reqResp.sendStatus(peer, localStatus));
} catch {
} catch (_e) {
// TODO: Failed to get peer latest status: downvote but don't disconnect
}
}
Expand All @@ -423,7 +423,7 @@ export class PeerManager {
* NOTE: Discovery should only add a new query if one isn't already queued.
*/
private heartbeat(): void {
// timer is safe without a try {} catch {}, in case of error the metric won't register and timer is GC'ed
// timer is safe without a try {} catch (_e) {}, in case of error the metric won't register and timer is GC'ed
const timer = this.metrics?.peerManager.heartbeatDuration.startTimer();

const connectedPeers = this.getConnectedPeerIds();
Expand Down
2 changes: 1 addition & 1 deletion packages/beacon-node/src/network/reqresp/rateLimit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ function getRequestCountFn<T extends ReqRespMethod>(
return (reqData: Uint8Array) => {
try {
return (type && fn(type.deserialize(reqData))) ?? 1;
} catch {
} catch (_e) {
return 1;
}
};
Expand Down
2 changes: 1 addition & 1 deletion packages/beacon-node/test/e2e/sync/finalizedSync.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ describe("sync / finalized sync", function () {
try {
await waitForSynced;
loggerNodeB.info("Node B synced to Node A, received head block", {slot: head.message.slot});
} catch {
} catch (_e) {
assert.fail("Failed to sync to other node in time");
}
});
Expand Down
12 changes: 6 additions & 6 deletions packages/beacon-node/test/spec/bls/bls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function aggregate_verify(input: {pubkeys: string[]; messages: string[]; signatu
pubkeys.map((pk) => PublicKey.fromHex(pk)),
Signature.fromHex(signature)
);
} catch {
} catch (_e) {
return false;
}
}
Expand Down Expand Up @@ -76,7 +76,7 @@ function fast_aggregate_verify(input: {pubkeys: string[]; message: string; signa
pubkeys.map((hex) => PublicKey.fromHex(hex, true)),
Signature.fromHex(signature, true)
);
} catch {
} catch (_e) {
return false;
}
}
Expand All @@ -101,7 +101,7 @@ function batch_verify(input: {pubkeys: string[]; messages: string[]; signatures:
sig: Signature.fromHex(signatures[i], true),
}))
);
} catch {
} catch (_e) {
return false;
}
}
Expand Down Expand Up @@ -135,7 +135,7 @@ function verify(input: {pubkey: string; message: string; signature: string}): bo
const {pubkey, message, signature} = input;
try {
return _verify(fromHexString(message), PublicKey.fromHex(pubkey), Signature.fromHex(signature));
} catch {
} catch (_e) {
return false;
}
}
Expand All @@ -151,7 +151,7 @@ function deserialization_G1(input: {pubkey: string}): boolean {
try {
PublicKey.fromHex(input.pubkey, true);
return true;
} catch {
} catch (_e) {
return false;
}
}
Expand All @@ -167,7 +167,7 @@ function deserialization_G2(input: {signature: string}): boolean {
try {
Signature.fromHex(input.signature, true);
return true;
} catch {
} catch (_e) {
return false;
}
}
14 changes: 7 additions & 7 deletions packages/beacon-node/test/spec/general/bls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ function aggregate(input: string[]): string | null {
const pks = input.map((pkHex) => Signature.fromHex(pkHex));
const agg = aggregateSignatures(pks);
return agg.toHex();
} catch {
} catch (_e) {
return null;
}
}
Expand All @@ -95,7 +95,7 @@ function aggregate_verify(input: {pubkeys: string[]; messages: string[]; signatu
pubkeys.map((pk) => PublicKey.fromHex(pk)),
Signature.fromHex(signature)
);
} catch {
} catch (_e) {
return false;
}
}
Expand All @@ -114,7 +114,7 @@ function eth_aggregate_pubkeys(input: string[]): string | null {

try {
return aggregateSerializedPublicKeys(input.map((hex) => fromHexString(hex))).toHex();
} catch {
} catch (_e) {
return null;
}
}
Expand Down Expand Up @@ -146,7 +146,7 @@ function eth_fast_aggregate_verify(input: {pubkeys: string[]; message: string; s
pubkeys.map((hex) => PublicKey.fromHex(hex)),
Signature.fromHex(signature)
);
} catch {
} catch (_e) {
return false;
}
}
Expand All @@ -168,7 +168,7 @@ function fast_aggregate_verify(input: {pubkeys: string[]; message: string; signa
pubkeys.map((hex) => PublicKey.fromHex(hex, true)),
Signature.fromHex(signature, true)
);
} catch {
} catch (_e) {
return false;
}
}
Expand All @@ -183,7 +183,7 @@ function sign(input: {privkey: string; message: string}): string | null {
const {privkey, message} = input;
try {
return SecretKey.fromHex(privkey).sign(fromHexString(message)).toHex();
} catch {
} catch (_e) {
return null;
}
}
Expand All @@ -199,7 +199,7 @@ function verify(input: {pubkey: string; message: string; signature: string}): bo
const {pubkey, message, signature} = input;
try {
return _verify(fromHexString(message), PublicKey.fromHex(pubkey), Signature.fromHex(signature));
} catch {
} catch (_e) {
return false;
}
}
2 changes: 1 addition & 1 deletion packages/beacon-node/test/unit/monitoring/remoteService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ function validateClientStats(data: ReceivedData, schema: ClientStatsSchema): voi
schema.forEach((s) => {
try {
expect(data[s.key]).toBeInstanceOf(s.type);
} catch {
} catch (_e) {
throw new Error(
`Validation of property "${s.key}" failed. Expected type "${s.type}" but received "${typeof data[s.key]}".`
);
Expand Down
2 changes: 1 addition & 1 deletion packages/beacon-node/test/unit/util/kzg.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ describe("C-KZG", () => {
blobSidecars.forEach(async (blobSidecar) => {
try {
await validateGossipBlobSidecar(chain, blobSidecar, blobSidecar.index);
} catch {
} catch (_e) {
// We expect some error from here
// console.log(error);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/beacon-node/test/utils/runEl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ async function waitForELOnline(url: string, signal: AbortSignal): Promise<void>
console.log("Waiting for few seconds for EL to fully setup, for e.g. unlock the account...");
await sleep(5000, signal);
return; // Done
} catch {
} catch (_e) {
await sleep(1000, signal);
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/cmds/beacon/initPeerIdAndEnr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,14 @@ export async function initPeerIdAndEnr(
// attempt to read stored peer id
try {
peerId = await readPeerId(peerIdFile);
} catch {
} catch (_e) {
logger.warn("Unable to read peerIdFile, creating a new peer id");
return {...(await newPeerIdAndENR()), newEnr: true};
}
// attempt to read stored enr
try {
enr = SignableENR.decodeTxt(fs.readFileSync(enrFile, "utf-8"), createPrivateKeyFromPeerId(peerId).privateKey);
} catch {
} catch (_e) {
logger.warn("Unable to decode stored local ENR, creating a new ENR");
enr = SignableENR.createV4(createPrivateKeyFromPeerId(peerId).privateKey);
return {peerId, enr, newEnr: true};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export async function decryptKeystoreDefinitions(
opts.logger.debug("Loaded keystores via keystore cache");

return signers;
} catch {
} catch (_e) {
// Some error loading the cache, ignore and invalidate cache
await clearKeystoreCache(opts.cacheFilePath);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ try {
} else {
maxPoolSize = (await import("node:os")).availableParallelism();
}
} catch {
} catch (_e) {
maxPoolSize = 8;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/networks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export function readBootnodes(bootnodesFilePath: string): string[] {
for (const enrStr of bootnodes) {
try {
ENR.decodeTxt(enrStr);
} catch {
} catch (_e) {
throw new Error(`Invalid ENR found in ${bootnodesFilePath}:\n ${enrStr}`);
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/options/beaconNodeOptions/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export function parseArgs(args: NetworkArgs): IBeaconNodeOptions["network"] {
for (const enrStr of bootEnrs) {
try {
ENR.decodeTxt(enrStr);
} catch {
} catch (_e) {
throw new YargsError(`Provided ENR in bootnodes is invalid:\n ${enrStr}`);
}
}
Expand Down
Loading

0 comments on commit fba83fa

Please sign in to comment.