Unused error variables in catch block are not allowed (#24487)

This commit is contained in:
Alisa
2026-04-01 21:33:07 -07:00
committed by GitHub
parent 84936dc85d
commit 3344f6849c
92 changed files with 162 additions and 157 deletions
@@ -404,12 +404,12 @@ ${output.result}`;
);
await removeInputBlocker(browserManager, signal);
await removeAutomationOverlay(browserManager, signal);
} catch (_err) {
} catch {
// Ignore errors for individual pages
}
}
}
} catch (_) {
} catch {
// Ignore errors for removing the overlays.
}
}
+1 -1
View File
@@ -1408,7 +1408,7 @@ Important Rules:
Object.assign(args, parsed);
}
return { args };
} catch (_) {
} catch {
return {
args: {},
error: `Failed to parse JSON arguments for tool "${functionCall.name}": ${functionCall.args}. Ensure you provide a valid JSON object.`,
@@ -59,7 +59,7 @@ export function sanitizeAdminSettings(
}
}
}
} catch (_e) {
} catch {
// Ignore parsing errors
}
}
+1 -1
View File
@@ -491,7 +491,7 @@ export class CodeAssistServer implements ContentGenerator {
const chunk = bufferedLines.join('\n');
try {
yield JSON.parse(chunk);
} catch (_e) {
} catch {
if (server.config) {
logInvalidChunk(
server.config,
@@ -138,7 +138,7 @@ class ExtensionIntegrityStore {
let rawStore: IntegrityStore;
try {
rawStore = IntegrityStoreSchema.parse(JSON.parse(content));
} catch (_) {
} catch {
throw new Error(
`Failed to parse extension integrity store. ${resetInstruction}}`,
);
+2 -2
View File
@@ -258,7 +258,7 @@ export class ProjectRegistry {
diskCollision = true;
break;
}
} catch (_e) {
} catch {
// If we can't read it, assume it's someone else's to be safe
diskCollision = true;
break;
@@ -274,7 +274,7 @@ export class ProjectRegistry {
try {
await this.ensureOwnershipMarkers(candidate, projectPath);
return candidate;
} catch (_e) {
} catch {
// Someone might have claimed it between our check and our write.
// Try next candidate.
continue;
+1 -1
View File
@@ -147,7 +147,7 @@ export class BaseLlmClient {
// We don't use the result, just check if it's valid JSON
JSON.parse(this.cleanJsonResponse(text, model));
return false; // It's valid, don't retry
} catch (_e) {
} catch {
return true; // It's not valid, retry
}
};
+1 -1
View File
@@ -1487,7 +1487,7 @@ ${JSON.stringify(
break;
}
}
} catch (_) {
} catch {
// If the test framework times out, that also demonstrates the infinite loop
}
+1 -1
View File
@@ -50,7 +50,7 @@ const TEST_CHECKPOINT_FILE_PATH = path.join(
async function cleanupLogAndCheckpointFiles() {
try {
await fs.rm(TEST_GEMINI_DIR, { recursive: true, force: true });
} catch (_error) {
} catch {
// Ignore errors, as the directory may not exist, which is fine.
}
}
+4 -4
View File
@@ -59,7 +59,7 @@ export function encodeTagName(str: string): string {
export function decodeTagName(str: string): string {
try {
return decodeURIComponent(str);
} catch (_e) {
} catch {
// Fallback for old, potentially malformed encoding
return str.replace(/%([0-9A-F]{2})/g, (_, hex) =>
String.fromCharCode(parseInt(hex, 16)),
@@ -134,7 +134,7 @@ export class Logger {
try {
await fs.rename(this.logFilePath, backupPath);
debugLogger.debug(`Backed up corrupted log file to ${backupPath}`);
} catch (_backupError) {
} catch {
// If rename fails (e.g. file doesn't exist), no need to log an error here as the primary error (e.g. invalid JSON) is already handled.
}
}
@@ -153,7 +153,7 @@ export class Logger {
let fileExisted = true;
try {
await fs.access(this.logFilePath);
} catch (_e) {
} catch {
fileExisted = false;
}
this.logs = await this._readLogFile();
@@ -277,7 +277,7 @@ export class Logger {
// then this instance can increment its idea of the next messageId for this session.
this.messageId = writtenEntry.messageId + 1;
}
} catch (_error) {
} catch {
// Error already logged by _updateLogFile or _readLogFile
}
}
@@ -294,7 +294,7 @@ export class LoggingContentGenerator implements ContentGenerator {
if (charCodes.every((code) => !isNaN(code))) {
response.data = String.fromCharCode(...charCodes);
}
} catch (_e) {
} catch {
// If parsing fails, just leave it alone
}
}
+4 -4
View File
@@ -370,9 +370,9 @@ export class HookRunner {
if (process.platform === 'win32' && child.pid) {
try {
execSync(`taskkill /pid ${child.pid} /f /t`, { timeout: 2000 });
} catch (_e) {
} catch (e) {
// Ignore errors if process is already dead or access denied
debugLogger.debug(`Taskkill failed: ${_e}`);
debugLogger.debug(`Taskkill failed: ${e}`);
}
} else {
child.kill('SIGTERM');
@@ -384,9 +384,9 @@ export class HookRunner {
if (process.platform === 'win32' && child.pid) {
try {
execSync(`taskkill /pid ${child.pid} /f /t`, { timeout: 2000 });
} catch (_e) {
} catch (e) {
// Ignore
debugLogger.debug(`Taskkill failed: ${_e}`);
debugLogger.debug(`Taskkill failed: ${e}`);
}
} else {
child.kill('SIGKILL');
+3 -3
View File
@@ -354,7 +354,7 @@ export class IdeClient {
if (parsedJson && parsedJson.content === null) {
return undefined;
}
} catch (_e) {
} catch {
logger.debug(
`Invalid JSON in closeDiff response for ${filePath}:`,
textPart.text,
@@ -602,7 +602,7 @@ export class IdeClient {
await this.discoverTools();
this.setState(IDEConnectionStatus.Connected);
return true;
} catch (_error) {
} catch {
if (transport) {
try {
await transport.close();
@@ -636,7 +636,7 @@ export class IdeClient {
await this.discoverTools();
this.setState(IDEConnectionStatus.Connected);
return true;
} catch (_error) {
} catch {
if (transport) {
try {
await transport.close();
@@ -125,7 +125,7 @@ export async function getConnectionConfigFromFile(
const portFileContents = await fs.promises.readFile(portFile, 'utf8');
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return JSON.parse(portFileContents);
} catch (_) {
} catch {
// For newer extension versions, the file name matches the pattern
// /^gemini-ide-server-${pid}-\d+\.json$/. If multiple IDE
// windows are open, multiple files matching the pattern are expected to
+3 -3
View File
@@ -186,7 +186,7 @@ class VsCodeInstaller implements IdeInstaller {
success: true,
message: `${this.ideInfo.displayName} companion extension was installed successfully.`,
};
} catch (_error) {
} catch {
return {
success: false,
message: `Failed to install ${this.ideInfo.displayName} companion extension. Please try installing '${GEMINI_CLI_COMPANION_EXTENSION_NAME}' manually from the ${this.ideInfo.displayName} extension marketplace.`,
@@ -236,7 +236,7 @@ class PositronInstaller implements IdeInstaller {
success: true,
message: `${this.ideInfo.displayName} companion extension was installed successfully.`,
};
} catch (_error) {
} catch {
return {
success: false,
message: `Failed to install ${this.ideInfo.displayName} companion extension. Please try installing '${GEMINI_CLI_COMPANION_EXTENSION_NAME}' manually from the ${this.ideInfo.displayName} extension marketplace.`,
@@ -306,7 +306,7 @@ class AntigravityInstaller implements IdeInstaller {
success: true,
message: `${this.ideInfo.displayName} companion extension was installed successfully.`,
};
} catch (_error) {
} catch {
return {
success: false,
message: `Failed to install ${this.ideInfo.displayName} companion extension. Please try installing '${GEMINI_CLI_COMPANION_EXTENSION_NAME}' manually from the ${this.ideInfo.displayName} extension marketplace.`,
+3 -3
View File
@@ -49,7 +49,7 @@ async function getProcessTableWindows(): Promise<Map<number, ProcessInfo>> {
try {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
processes = JSON.parse(stdout);
} catch (_e) {
} catch {
return processMap;
}
@@ -67,7 +67,7 @@ async function getProcessTableWindows(): Promise<Map<number, ProcessInfo>> {
});
}
}
} catch (_e) {
} catch {
// Fallback or error handling if PowerShell fails
}
return processMap;
@@ -102,7 +102,7 @@ async function getProcessInfo(pid: number): Promise<{
name: processName,
command: fullCommand,
};
} catch (_e) {
} catch {
return { parentPid: 0, name: '', command: '' };
}
}
+1 -1
View File
@@ -98,7 +98,7 @@ export class AllowedPathChecker implements InProcessChecker {
// Fallback if nothing exists (unlikely if root exists)
return resolved;
} catch (_error) {
} catch {
return null;
}
}
@@ -148,7 +148,7 @@ export function buildSeatbeltProfile(options: SeatbeltArgsOptions): string {
addedPaths.add(resolved);
profile += `(allow file-read* (subpath "${escapeSchemeString(resolved)}"))\n`;
}
} catch (_e) {
} catch {
// Ignore paths that do not exist or are inaccessible
}
}
+6 -6
View File
@@ -14,15 +14,15 @@ export function isErrnoException(e: unknown): e is NodeJS.ErrnoException {
export function tryRealpath(p: string): string {
try {
return fs.realpathSync(p);
} catch (_e) {
if (isErrnoException(_e) && _e.code === 'ENOENT') {
} catch (e) {
if (isErrnoException(e) && e.code === 'ENOENT') {
const parentDir = path.dirname(p);
if (parentDir === p) {
return p;
}
return path.join(tryRealpath(parentDir), path.basename(p));
}
throw _e;
throw e;
}
}
@@ -52,7 +52,7 @@ export function resolveGitWorktreePaths(workspacePath: string): {
if (tryRealpath(backlink) === tryRealpath(gitPath)) {
isValid = true;
}
} catch (_e) {
} catch {
// Fallback for submodules: check core.worktree in config
try {
const configPath = path.join(resolvedWorktreeGitDir, 'config');
@@ -67,7 +67,7 @@ export function resolveGitWorktreePaths(workspacePath: string): {
isValid = true;
}
}
} catch (_e2) {
} catch {
// Ignore
}
}
@@ -85,7 +85,7 @@ export function resolveGitWorktreePaths(workspacePath: string): {
};
}
}
} catch (_e) {
} catch {
// Ignore if .git doesn't exist, isn't readable, etc.
}
return {};
+1 -1
View File
@@ -901,7 +901,7 @@ export class Scheduler {
} as ScheduledToolCall,
signal,
);
} catch (_e) {
} catch {
// Fallback to normal error handling if parsing/looping fails
}
}
+1 -1
View File
@@ -46,7 +46,7 @@ export class GitService {
try {
await spawnAsync('git', ['--version']);
return true;
} catch (_error) {
} catch {
return false;
}
}
@@ -313,7 +313,7 @@ export class ShellExecutionService {
shellExecutionConfig,
ptyInfo,
);
} catch (_e) {
} catch {
// Fallback to child_process
}
}
+1 -1
View File
@@ -1817,7 +1817,7 @@ export async function connectToMcpServer(
await mcpClient.notification({
method: 'notifications/roots/list_changed',
});
} catch (_) {
} catch {
// If this fails, its almost certainly because the connection was closed
// and we should just stop listening for future directory changes.
unlistenDirectories?.();
+1 -1
View File
@@ -830,7 +830,7 @@ describe('DiscoveredMCPTool', () => {
if (expectError) {
try {
await invocation.execute(controller.signal);
} catch (_error) {
} catch {
// Expected error
}
} else {
+1 -1
View File
@@ -678,7 +678,7 @@ describe('RipGrepTool', () => {
stdout.write(match + '\n');
linesPushed++;
}
} catch (_e) {
} catch {
clearInterval(pushInterval);
}
}, 1);
+2 -2
View File
@@ -749,7 +749,7 @@ export class ShellToolInvocation extends BaseToolInvocation<
) {
currentPath = path.dirname(currentPath);
}
} catch (_e) {
} catch {
/* ignore */
}
while (currentPath.length > 1) {
@@ -770,7 +770,7 @@ export class ShellToolInvocation extends BaseToolInvocation<
}
currentPath = path.dirname(currentPath);
}
} catch (_e) {
} catch {
// ignore
}
}
+1 -1
View File
@@ -367,7 +367,7 @@ export abstract class BaseToolInvocation<
try {
void this.messageBus.publish(request);
} catch (_error) {
} catch {
cleanup();
resolve('allow');
}
+2 -2
View File
@@ -73,7 +73,7 @@ function checkRateLimit(url: string): {
history.push(now);
hostRequestHistory.set(hostname, history);
return { allowed: true };
} catch (_e) {
} catch {
// If URL parsing fails, we fallback to allowed (should be caught by parsePrompt anyway)
return { allowed: true };
}
@@ -132,7 +132,7 @@ export function parsePrompt(text: string): {
`Unsupported protocol in URL: "${token}". Only http and https are supported.`,
);
}
} catch (_) {
} catch {
// new URL() threw, so it's malformed according to WHATWG standard
errors.push(`Malformed URL detected: "${token}".`);
}
@@ -95,7 +95,7 @@ export class XcodeMcpBridgeFixTransport
// If successful, populate structuredContent
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
result.structuredContent = parsed;
} catch (_) {
} catch {
// Ignored: Content is likely plain text, not JSON.
}
}
+1 -1
View File
@@ -176,7 +176,7 @@ export function getCheckpointInfoList(
checkpoint: file.replace('.json', ''),
});
}
} catch (_e) {
} catch {
// Ignore invalid JSON files
}
}
+2 -2
View File
@@ -66,7 +66,7 @@ export function parseAndFormatApiError(
if (isApiError(nestedError)) {
finalMessage = nestedError.error.message;
}
} catch (_e) {
} catch {
// It's not a nested JSON error, so we just use the message as is.
}
let text = `[API Error: ${finalMessage} (Status: ${parsedError.error.status})]`;
@@ -75,7 +75,7 @@ export function parseAndFormatApiError(
}
return text;
}
} catch (_e) {
} catch {
// Not a valid JSON, fall through and return the original message.
}
return `[API Error: ${error}]`;
+1 -1
View File
@@ -576,7 +576,7 @@ export async function fileExists(filePath: string): Promise<boolean> {
try {
await fsPromises.access(filePath, fs.constants.F_OK);
return true;
} catch (_: unknown) {
} catch {
return false;
}
}
@@ -80,7 +80,7 @@ export async function crawl(options: CrawlOptions): Promise<string[]> {
}
results = await api.crawl(options.crawlDirectory).withPromise();
} catch (_e) {
} catch {
// The directory probably doesn't exist.
return [];
}
+2 -2
View File
@@ -27,14 +27,14 @@ export const getPty = async (): Promise<PtyImplementation> => {
const module = await import(lydell);
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
return { module, name: 'lydell-node-pty' };
} catch (_e) {
} catch {
try {
const nodePty = 'node-pty';
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const module = await import(nodePty);
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
return { module, name: 'node-pty' };
} catch (_e2) {
} catch {
return null;
}
}
+2 -2
View File
@@ -37,7 +37,7 @@ export class GitIgnoreParser implements GitIgnoreFilter {
let content: string;
try {
content = fs.readFileSync(patternsFilePath, 'utf-8');
} catch (_error) {
} catch {
return ignore();
}
@@ -189,7 +189,7 @@ export class GitIgnoreParser implements GitIgnoreFilter {
// Extra patterns (like .geminiignore) have final precedence
return ig.add(this.processedExtraPatterns).ignores(normalizedPath);
} catch (_error) {
} catch {
return false;
}
}
+2 -2
View File
@@ -35,7 +35,7 @@ export function isGitRepository(directory: string): boolean {
}
return false;
} catch (_error) {
} catch {
// If any filesystem error occurs, assume not a git repo
return false;
}
@@ -67,7 +67,7 @@ export function findGitRoot(directory: string): string | null {
}
return null;
} catch (_error) {
} catch {
return null;
}
}
+5 -5
View File
@@ -159,7 +159,7 @@ export function parseGoogleApiError(error: unknown): GoogleApiError | null {
if (typeof errorObj === 'string') {
try {
errorObj = JSON.parse(sanitizeJsonString(errorObj));
} catch (_) {
} catch {
// Not a JSON string, can't parse.
return null;
}
@@ -200,7 +200,7 @@ export function parseGoogleApiError(error: unknown): GoogleApiError | null {
// The message is a JSON string, but not a nested error object.
break;
}
} catch (_error) {
} catch {
// It wasn't a JSON string, so we've drilled down as far as we can.
break;
}
@@ -284,7 +284,7 @@ function fromGaxiosError(errorObj: object): ErrorShape | undefined {
try {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
data = JSON.parse(sanitizeJsonString(data));
} catch (_) {
} catch {
// Not a JSON string, can't parse.
}
}
@@ -334,7 +334,7 @@ function fromApiError(errorObj: object): ErrorShape | undefined {
try {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
data = JSON.parse(sanitizeJsonString(data));
} catch (_) {
} catch {
// Not a JSON string, can't parse.
// Try one more fallback: look for the first '{' and last '}'
if (typeof data === 'string') {
@@ -346,7 +346,7 @@ function fromApiError(errorObj: object): ErrorShape | undefined {
data = JSON.parse(
sanitizeJsonString(data.substring(firstBrace, lastBrace + 1)),
);
} catch (__) {
} catch {
// Still failed
}
}
+1 -1
View File
@@ -60,7 +60,7 @@ export class IgnoreFileParser implements IgnoreFileFilter {
let content: string;
try {
content = fs.readFileSync(patternsFilePath, 'utf-8');
} catch (_error) {
} catch {
debugLogger.debug(
`Ignore file not found: ${patternsFilePath}, continue without it.`,
);
+1 -1
View File
@@ -368,7 +368,7 @@ export function resolveToRealPath(pathStr: string): string {
}
resolvedPath = decodeURIComponent(resolvedPath);
} catch (_e) {
} catch {
// Ignore error (e.g. malformed URI), keep path from previous step
}
+2 -2
View File
@@ -49,7 +49,7 @@ export async function killProcessGroup(options: KillOptions): Promise<void> {
// Invoke taskkill to ensure the entire tree is terminated and any orphaned descendant processes are reaped.
try {
await spawnAsync('taskkill', ['/pid', pid.toString(), '/f', '/t']);
} catch (_e) {
} catch {
// Ignore errors if the process tree is already dead
}
return;
@@ -72,7 +72,7 @@ export async function killProcessGroup(options: KillOptions): Promise<void> {
}
}
}
} catch (_e) {
} catch {
// Fallback to specific process kill if group kill fails or on error
if (!isExited()) {
if (pty) {
@@ -23,7 +23,7 @@ function validateUrl(url: string): void {
try {
parsedUrl = new URL(url);
} catch (_error) {
} catch {
throw new Error(`Invalid URL: ${url}`);
}
@@ -51,7 +51,7 @@ describe('execStreaming (Integration)', () => {
for await (const line of generator) {
lines.push(line);
}
} catch (_e) {
} catch {
// ignore
}
return lines;
+2 -2
View File
@@ -483,7 +483,7 @@ export function parseBashCommandDetails(
'Syntax Errors:',
syntaxErrors,
);
} catch (_e) {
} catch {
// Ignore query errors
} finally {
query?.delete();
@@ -945,7 +945,7 @@ export async function* execStreaming(
if (!finished && child.exitCode === null && !child.killed) {
try {
child.kill();
} catch (_e) {
} catch {
// ignore error if process is already dead
}
killedByGenerator = true;
+1 -1
View File
@@ -88,7 +88,7 @@ export function getSystemEncoding(): string | null {
locale = execSync('locale charmap', { encoding: 'utf8' })
.toString()
.trim();
} catch (_e) {
} catch {
debugLogger.warn('Failed to get locale charmap.');
return null;
}
+2 -2
View File
@@ -188,7 +188,7 @@ export class WorkspaceContext {
}
}
return false;
} catch (_error) {
} catch {
return false;
}
}
@@ -216,7 +216,7 @@ export class WorkspaceContext {
}
}
return false;
} catch (_error) {
} catch {
return false;
}
}