diff --git a/packages/core/src/ide/ide-installer.ts b/packages/core/src/ide/ide-installer.ts index 52dcb6fb4ce..cefb1b05039 100644 --- a/packages/core/src/ide/ide-installer.ts +++ b/packages/core/src/ide/ide-installer.ts @@ -136,8 +136,8 @@ class VsCodeInstaller implements IdeInstaller { ['--install-extension', vsixPath, '--force'], { stdio: 'pipe', - shell: os.platform() === 'win32' && commandPath.endsWith('.cmd') - } + shell: os.platform() === 'win32' && commandPath.endsWith('.cmd'), + }, ); return { success: true, diff --git a/packages/core/src/tools/edit.ts b/packages/core/src/tools/edit.ts index 333232035e5..f8e1c36ec54 100644 --- a/packages/core/src/tools/edit.ts +++ b/packages/core/src/tools/edit.ts @@ -22,7 +22,7 @@ import { ToolErrorType } from './tool-error.js'; import { Type } from '@google/genai'; import { SchemaValidator } from '../utils/schemaValidator.js'; import { makeRelative, shortenPath } from '../utils/paths.js'; -import { isNodeError } from '../utils/errors.js'; +import { getErrorMessage, isNodeError } from '../utils/errors.js'; import { Config, ApprovalMode } from '../config/config.js'; import { ensureCorrectEdit } from '../utils/editCorrector.js'; import { DEFAULT_DIFF_OPTIONS, getDiffStat } from './diffOptions.js'; @@ -229,8 +229,8 @@ class EditToolInvocation implements ToolInvocation { let editData: CalculatedEdit; try { editData = await this.calculateEdit(this.params, abortSignal); - } catch (error) { - const errorMsg = error instanceof Error ? error.message : String(error); + } catch (error: unknown) { + const errorMsg = getErrorMessage(error); console.log(`Error preparing edit: ${errorMsg}`); return false; } @@ -316,8 +316,8 @@ class EditToolInvocation implements ToolInvocation { let editData: CalculatedEdit; try { editData = await this.calculateEdit(this.params, signal); - } catch (error) { - const errorMsg = error instanceof Error ? error.message : String(error); + } catch (error: unknown) { + const errorMsg = getErrorMessage(error); return { llmContent: `Error preparing edit: ${errorMsg}`, returnDisplay: `Error preparing edit: ${errorMsg}`, @@ -390,8 +390,8 @@ class EditToolInvocation implements ToolInvocation { llmContent: llmSuccessMessageParts.join(' '), returnDisplay: displayResult, }; - } catch (error) { - const errorMsg = error instanceof Error ? error.message : String(error); + } catch (error: unknown) { + const errorMsg = getErrorMessage(error); return { llmContent: `Error executing edit: ${errorMsg}`, returnDisplay: `Error writing file: ${errorMsg}`, diff --git a/packages/core/src/utils/errors.test.ts b/packages/core/src/utils/errors.test.ts index ec42a3f954f..59cc5a37f53 100644 --- a/packages/core/src/utils/errors.test.ts +++ b/packages/core/src/utils/errors.test.ts @@ -1,10 +1,17 @@ +/** + * @license + * Copyright 2025 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + import { describe, it, expect } from 'vitest'; + import { toFriendlyError, BadRequestError, UnauthorizedError, ForbiddenError, -} from './errors'; +} from './errors.js'; describe('toFriendlyError', () => { it('should return the original error if it is not an object', () => { diff --git a/packages/core/src/utils/fetch.test.ts b/packages/core/src/utils/fetch.test.ts index 02d7c6f2df4..d00012cc1a8 100644 --- a/packages/core/src/utils/fetch.test.ts +++ b/packages/core/src/utils/fetch.test.ts @@ -91,7 +91,8 @@ describe('fetchWithTimeout', () => { it('should throw FetchError with ETIMEDOUT code when request times out', async () => { // Mock fetch to simulate timeout behavior (fetch as unknown as ReturnType).mockImplementation( - (url: string, options: { signal: AbortSignal }) => new Promise((_, reject) => { + (url: string, options: { signal: AbortSignal }) => + new Promise((_, reject) => { if (options.signal.aborted) { const error = new Error('The operation was aborted'); (error as any).code = 'ABORT_ERR';