mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-05-15 14:23:02 -07:00
fix(core): align logging and error handling with strict development rules
Addressed reviewer feedback by replacing process.stderr.write with debugLogger.error in config.ts and using isNodeError in storage.ts to adhere to codebase standards.
This commit is contained in:
@@ -3423,8 +3423,8 @@ describe('Plans Directory Initialization', () => {
|
||||
|
||||
it('should log a warning if the plan directory path is blocked by an existing file (EEXIST) in PLAN mode', async () => {
|
||||
const writeSpy = vi
|
||||
.spyOn(process.stderr, 'write')
|
||||
.mockImplementation(() => true);
|
||||
.spyOn(debugLogger, 'error')
|
||||
.mockImplementation(() => {});
|
||||
vi.spyOn(fs, 'mkdirSync').mockImplementation(() => {
|
||||
const err = new Error('File exists') as NodeJS.ErrnoException;
|
||||
err.code = 'EEXIST';
|
||||
@@ -3449,8 +3449,8 @@ describe('Plans Directory Initialization', () => {
|
||||
|
||||
it('should log a warning if mkdirSync fails during getPlansDir (e.g. EACCES) in PLAN mode', async () => {
|
||||
const writeSpy = vi
|
||||
.spyOn(process.stderr, 'write')
|
||||
.mockImplementation(() => true);
|
||||
.spyOn(debugLogger, 'error')
|
||||
.mockImplementation(() => {});
|
||||
vi.spyOn(fs, 'mkdirSync').mockImplementation(() => {
|
||||
const err = new Error('Permission denied') as NodeJS.ErrnoException;
|
||||
err.code = 'EACCES';
|
||||
|
||||
@@ -2275,20 +2275,17 @@ export class Config implements McpContext, AgentLoopContext {
|
||||
|
||||
let realPlansDir = plansDir;
|
||||
try {
|
||||
const resolved = resolveToRealPath(plansDir);
|
||||
if (resolved) {
|
||||
realPlansDir = resolved;
|
||||
}
|
||||
realPlansDir = resolveToRealPath(plansDir);
|
||||
} catch {
|
||||
// Ignore failures in mock environments
|
||||
}
|
||||
this.workspaceContext.addDirectory(realPlansDir);
|
||||
this.initializedPlanDirs.add(plansDir);
|
||||
} catch (e: unknown) {
|
||||
const errorMessage = e instanceof Error ? e.message : String(e);
|
||||
process.stderr.write(
|
||||
`Failed to initialize active plan directory at '${plansDir}': ${errorMessage}\n`,
|
||||
debugLogger.error(
|
||||
`Failed to initialize active plan directory at '${plansDir}': ${getErrorMessage(e)}`,
|
||||
);
|
||||
} finally {
|
||||
this.initializedPlanDirs.add(plansDir);
|
||||
}
|
||||
} else if (!this.planEnabled) {
|
||||
this.initializedPlanDirs.add(plansDir);
|
||||
|
||||
@@ -18,6 +18,7 @@ import {
|
||||
} from '../utils/paths.js';
|
||||
import { ProjectRegistry } from './projectRegistry.js';
|
||||
import { StorageMigration } from './storageMigration.js';
|
||||
import { isNodeError } from '../utils/errors.js';
|
||||
|
||||
export const OAUTH_FILE = 'oauth_creds.json';
|
||||
const TMP_DIR_NAME = 'tmp';
|
||||
@@ -330,14 +331,7 @@ export class Storage {
|
||||
try {
|
||||
realResolvedPath = resolveToRealPath(resolvedPath);
|
||||
} catch (e: unknown) {
|
||||
if (
|
||||
!(
|
||||
e &&
|
||||
typeof e === 'object' &&
|
||||
'code' in e &&
|
||||
(e.code === 'ENOENT' || e.code === 'EISDIR')
|
||||
)
|
||||
) {
|
||||
if (!(isNodeError(e) && (e.code === 'ENOENT' || e.code === 'EISDIR'))) {
|
||||
throw e;
|
||||
}
|
||||
// Construct the fallback path safely against the real project root
|
||||
|
||||
Reference in New Issue
Block a user