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

View File

@@ -284,7 +284,7 @@ export class LinkExtensionCommand implements Command {
try {
await stat(sourceFilepath);
} catch (_error) {
} catch {
return { name: this.name, data: `Invalid source: ${sourceFilepath}` };
}

View File

@@ -130,7 +130,7 @@ export class ListCheckpointsCommand implements Command {
const checkpointDir = config.storage.getProjectTempCheckpointsDir();
try {
await fs.mkdir(checkpointDir, { recursive: true });
} catch (_e) {
} catch {
// Ignore
}
@@ -169,7 +169,7 @@ export class ListCheckpointsCommand implements Command {
name: this.name,
data: `Available Checkpoints:\n${formatted}`,
};
} catch (_error) {
} catch {
return {
name: this.name,
data: 'An unexpected error occurred while listing checkpoints.',

View File

@@ -25,7 +25,7 @@ async function pathExists(path: string) {
try {
await access(path);
return true;
} catch (_e) {
} catch {
return false;
}
}

View File

@@ -32,7 +32,7 @@ describe('mcp command', () => {
try {
await parser.parse('mcp');
} catch (_error) {
} catch {
// yargs might throw an error when demandCommand is not met
}

View File

@@ -121,7 +121,7 @@ async function testMCPConnection(
try {
// Use the same transport creation logic as core
transport = await createTransport(serverName, config, false, mcpContext);
} catch (_error) {
} catch {
await client.close();
return MCPServerStatus.DISCONNECTED;
}
@@ -135,7 +135,7 @@ async function testMCPConnection(
await client.close();
return MCPServerStatus.CONNECTED;
} catch (_error) {
} catch {
await transport.close();
return MCPServerStatus.DISCONNECTED;
}

View File

@@ -1064,7 +1064,7 @@ async function resolveWorktreeSettings(
if (isGeminiWorktree(toplevel, projectRoot)) {
worktreePath = toplevel;
}
} catch (_e) {
} catch {
return undefined;
}

View File

@@ -33,7 +33,7 @@ describe('copyExtension permissions', () => {
makeWritableSync(path.join(p, child)),
);
}
} catch (_e) {
} catch {
// Ignore errors during cleanup
}
};

View File

@@ -101,7 +101,7 @@ describe('ExtensionManager', () => {
themeManager.clearExtensionThemes();
try {
fs.rmSync(tempHomeDir, { recursive: true, force: true });
} catch (_e) {
} catch {
// Ignore
}
});

View File

@@ -63,7 +63,7 @@ export function loadInstallMetadata(
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
const metadata = JSON.parse(configContent) as ExtensionInstallMetadata;
return metadata;
} catch (_e) {
} catch {
return undefined;
}
}

View File

@@ -151,7 +151,7 @@ export async function fetchReleaseFromGithub(
return await fetchJson(
`https://api.github.com/repos/${owner}/${repo}/releases/latest`,
);
} catch (_) {
} catch {
// This can fail if there is no release marked latest. In that case
// we want to just try the pre-release logic below.
}

View File

@@ -612,7 +612,7 @@ export function loadEnvironment(
}
}
}
} catch (_e) {
} catch {
// Errors are ignored to match the behavior of `dotenv.config({ quiet: true })`.
}
}

View File

@@ -1712,7 +1712,7 @@ describe('runNonInteractive', () => {
input,
prompt_id: promptId,
});
} catch (_error) {
} catch {
// Expected exit
}

View File

@@ -65,7 +65,7 @@ const getSavedChatTags = async (
);
return chatDetails;
} catch (_err) {
} catch {
return [];
}
};

View File

@@ -198,7 +198,7 @@ export const directoryCommand: SlashCommand = {
alreadyAdded.push(trimmedPath);
continue;
}
} catch (_e) {
} catch {
// Path might not exist or be inaccessible.
// We'll let batchAddDirectories handle it later.
}

View File

@@ -321,7 +321,7 @@ async function exploreAction(
});
try {
await open(extensionsUrl);
} catch (_error) {
} catch {
context.ui.addItem({
type: MessageType.ERROR,
text: `Failed to open browser. Check out the extensions gallery at ${extensionsUrl}`,

View File

@@ -151,7 +151,7 @@ async function completion(
const files = await fs.readdir(checkpointDir);
const jsonFiles = files.filter((file) => file.endsWith('.json'));
return getTruncatedCheckpointNames(jsonFiles);
} catch (_err) {
} catch {
return [];
}
}

View File

@@ -76,7 +76,7 @@ export async function updateGitignore(gitRepoRoot: string): Promise<void> {
let fileExists = true;
try {
existingContent = await fs.promises.readFile(gitignorePath, 'utf8');
} catch (_error) {
} catch {
// File doesn't exist
fileExists = false;
}
@@ -168,8 +168,8 @@ async function downloadFiles({
async function createDirectory(dirPath: string): Promise<void> {
try {
await fs.promises.mkdir(dirPath, { recursive: true });
} catch (_error) {
debugLogger.debug(`Failed to create ${dirPath} directory:`, _error);
} catch (error) {
debugLogger.debug(`Failed to create ${dirPath} directory:`, error);
throw new Error(
`Unable to create ${dirPath} directory. Do you have file permissions in the current directory?`,
);
@@ -222,8 +222,8 @@ export const setupGithubCommand: SlashCommand = {
let gitRepoRoot: string;
try {
gitRepoRoot = getGitRepoRoot();
} catch (_error) {
debugLogger.debug(`Failed to get git repo root:`, _error);
} catch (error) {
debugLogger.debug(`Failed to get git repo root:`, error);
throw new Error(
'Unable to determine the GitHub repository. /setup-github must be run from a git repository.',
);

View File

@@ -450,7 +450,7 @@ function* emitKeys(
insertable: true,
sequence: decoded,
});
} catch (_e) {
} catch {
debugLogger.log('Failed to decode OSC 52 clipboard data');
}
}

View File

@@ -319,7 +319,7 @@ export function useAtCompletion(props: UseAtCompletionProps): void {
if (state.pattern !== null) {
dispatch({ type: 'SEARCH', payload: state.pattern });
}
} catch (_) {
} catch {
if (initEpoch.current === currentEpoch) {
dispatch({ type: 'ERROR' });
}

View File

@@ -51,7 +51,7 @@ describe('useConsoleMessages', () => {
for (const unmount of unmounts) {
try {
unmount();
} catch (_e) {
} catch {
// Ignore unmount errors
}
}
@@ -161,7 +161,7 @@ describe('useErrorCount', () => {
for (const unmount of unmounts) {
try {
unmount();
} catch (_e) {
} catch {
// Ignore unmount errors
}
}

View File

@@ -102,7 +102,7 @@ export const useFolderTrust = (
try {
await trustedFolders.setValue(cwd, trustLevel);
} catch (_e) {
} catch {
coreEvents.emitFeedback(
'error',
'Failed to save trust settings. Exiting Gemini CLI.',

View File

@@ -31,7 +31,7 @@ export function useGitBranchName(cwd: string): string | undefined {
);
setBranchName(hashStdout.toString().trim());
}
} catch (_error) {
} catch {
setBranchName(undefined);
}
}, [cwd, setBranchName]);
@@ -57,7 +57,7 @@ export function useGitBranchName(cwd: string): string | undefined {
fetchBranchName();
}
});
} catch (_watchError) {
} catch {
// Silently ignore watcher errors (e.g. permissions or file not existing),
// similar to how exec errors are handled.
// The branch name will simply not update automatically.

View File

@@ -141,7 +141,7 @@ export const usePermissionsModifyTrust = (
const folders = loadTrustedFolders();
try {
await folders.setValue(cwd, trustLevel);
} catch (_e) {
} catch {
coreEvents.emitFeedback(
'error',
'Failed to save trust settings. Your changes may not persist.',
@@ -159,7 +159,7 @@ export const usePermissionsModifyTrust = (
try {
await folders.setValue(cwd, pendingTrustLevel);
return true;
} catch (_e) {
} catch {
coreEvents.emitFeedback(
'error',
'Failed to save trust settings. Your changes may not persist.',

View File

@@ -135,7 +135,7 @@ export function interpolateColor(
const gradient = tinygradient(color1, color2);
const color = gradient.rgbAt(factor);
return color.toHexString();
} catch (_e) {
} catch {
return color1;
}
}

View File

@@ -108,7 +108,7 @@ function highlightAndRenderLine(
const renderedNode = renderHastNode(getHighlightedLine(), theme, undefined);
return renderedNode !== null ? renderedNode : strippedLine;
} catch (_error) {
} catch {
return stripAnsi(line);
}
}

View File

@@ -135,7 +135,7 @@ export async function getDirectorySuggestions(
.sort()
.slice(0, MAX_SUGGESTIONS)
.map((name) => resultPrefix + name + userSep);
} catch (_) {
} catch {
return [];
}
}

View File

@@ -43,7 +43,7 @@ export function runSyncCleanup() {
for (const fn of syncCleanupFunctions) {
try {
fn();
} catch (_) {
} catch {
// Ignore errors during cleanup.
}
}
@@ -67,7 +67,7 @@ export async function runExitCleanup() {
for (const fn of cleanupFunctions) {
try {
await fn();
} catch (_) {
} catch {
// Ignore errors during cleanup.
}
}
@@ -76,14 +76,14 @@ export async function runExitCleanup() {
// Close persistent browser sessions before disposing config
try {
await resetBrowserSession();
} catch (_) {
} catch {
// Ignore errors during browser cleanup
}
if (configForTelemetry) {
try {
await configForTelemetry.dispose();
} catch (_) {
} catch {
// Ignore errors during disposal
}
}
@@ -93,7 +93,7 @@ export async function runExitCleanup() {
if (configForTelemetry && isTelemetrySdkInitialized()) {
try {
await shutdownTelemetry(configForTelemetry);
} catch (_) {
} catch {
// Ignore errors during telemetry shutdown
}
}

View File

@@ -23,9 +23,9 @@ export const isGitHubRepository = (): boolean => {
const pattern = /github\.com/;
return pattern.test(remotes);
} catch (_error) {
} catch (error) {
// If any filesystem error occurs, assume not a git repo
debugLogger.debug(`Failed to get git remote:`, _error);
debugLogger.debug(`Failed to get git remote:`, error);
return false;
}
};
@@ -85,10 +85,10 @@ export const getLatestGitHubRelease = async (
}
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return releaseTag;
} catch (_error) {
} catch (error) {
debugLogger.debug(
`Failed to determine latest run-gemini-cli release:`,
_error,
error,
);
throw new Error(
`Unable to determine the latest run-gemini-cli release on GitHub.`,

View File

@@ -110,7 +110,7 @@ export function getInstallationInfo(
'Installed via Homebrew. Please update with "brew upgrade gemini-cli".',
};
}
} catch (_error) {
} catch {
// Brew is not installed or gemini-cli is not installed via brew.
// Continue to the next check.
}

View File

@@ -42,7 +42,7 @@ export function tryParseJSON(input: string): object | null {
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return parsed;
} catch (_err) {
} catch {
return null;
}
}

View File

@@ -60,7 +60,7 @@ export async function shouldUseCurrentUserInSandbox(): Promise<boolean> {
);
return true;
}
} catch (_err) {
} catch {
// Silently ignore if /etc/os-release is not found or unreadable.
// The default (false) will be applied in this case.
debugLogger.warn(

View File

@@ -43,7 +43,7 @@ describe('SessionSelector', () => {
// Clean up test files
try {
await fs.rm(tmpDir, { recursive: true, force: true });
} catch (_error) {
} catch {
// Ignore cleanup errors
}
});

View File

@@ -52,7 +52,7 @@ const homeDirectoryCheck: WarningCheck = {
return 'Warning you are running Gemini CLI in your home directory.\nThis warning can be disabled in /settings';
}
return null;
} catch (_err: unknown) {
} catch {
return 'Could not verify the current directory due to a file system error.';
}
},
@@ -73,7 +73,7 @@ const rootDirectoryCheck: WarningCheck = {
}
return null;
} catch (_err: unknown) {
} catch {
return 'Could not verify the current directory due to a file system error.';
}
},