Skip to content

Commit a8665aa

Browse files
Release Update
1 parent 252f3e9 commit a8665aa

File tree

5 files changed

+34
-5
lines changed

5 files changed

+34
-5
lines changed

src/commands/doctor.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,12 @@ export const doctorCommand = new Command('doctor')
4141
try {
4242
await listInstances();
4343
logger.info('✅ Network/Permissions OK (Can list instances)');
44-
} catch {
45-
logger.error('❌ Network/Permissions Check Failed (Cannot list instances)');
44+
} catch (error) {
45+
if (error instanceof Error && error.message.includes('Authentication required')) {
46+
logger.error('❌ Network/Permissions Check Failed: Authentication required');
47+
} else {
48+
logger.error('❌ Network/Permissions Check Failed (Cannot list instances)');
49+
}
4650
}
4751

4852
// Check Environment Variables

src/commands/list.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@ export const listCommand = new Command('list')
2828
})));
2929

3030
} catch (error) {
31-
logger.error('Failed to list instances', error);
31+
if (error instanceof Error && error.message.includes('Authentication required')) {
32+
logger.error(error.message);
33+
} else {
34+
logger.error('Failed to list instances', error);
35+
}
3236
process.exit(1);
3337
}
3438
});

src/commands/select.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ export const selectCommand = new Command('select')
3333
await writeConfig({ selectedInstance });
3434
logger.info(`Selected instance: ${selectedInstance}`);
3535
} catch (error) {
36-
logger.error('Failed to select instance', error);
36+
if (error instanceof Error && error.message.includes('Authentication required')) {
37+
logger.error(error.message);
38+
} else {
39+
logger.error('Failed to select instance', error);
40+
}
3741
process.exit(1);
3842
}
3943
});

src/commands/setup.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ export const setupCommand = new Command('setup')
122122
logger.info('Setup complete! You can now run "cloudsqlctl start" to start the proxy.');
123123

124124
} catch (error) {
125-
logger.error('Failed to list instances. Ensure you have permissions.', error);
125+
if (error instanceof Error && error.message.includes('Authentication required')) {
126+
logger.error(error.message);
127+
} else {
128+
logger.error('Failed to list instances. Ensure you have permissions.', error);
129+
}
126130
}
127131
});

src/core/gcloud.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@ export interface GcloudInstance {
1111
state: string;
1212
}
1313

14+
function isAuthError(error: unknown): boolean {
15+
const err = error as { stderr?: string };
16+
if (!err?.stderr) return false;
17+
const { stderr } = err;
18+
return stderr.includes('Reauthentication failed') ||
19+
stderr.includes('gcloud auth login') ||
20+
stderr.includes('RefreshError') ||
21+
stderr.includes('cannot prompt during non-interactive execution');
22+
}
23+
1424
async function getGcloudCommand(): Promise<string> {
1525
const config = await readConfig();
1626
return config.gcloudPath || 'gcloud';
@@ -22,6 +32,9 @@ export async function listInstances(): Promise<GcloudInstance[]> {
2232
const { stdout } = await execa(cmd, ['sql', 'instances', 'list', '--format=json']);
2333
return JSON.parse(stdout);
2434
} catch (error) {
35+
if (isAuthError(error)) {
36+
throw new Error('Authentication required. Please run "cloudsqlctl auth login".');
37+
}
2538
logger.error('Failed to list instances', error);
2639
throw error;
2740
}

0 commit comments

Comments
 (0)