mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-29 15:30:40 -07:00
fix(core): prioritize detailed error messages for code assist setup (#17852)
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
import type {
|
||||
ClientMetadata,
|
||||
GeminiUserTier,
|
||||
IneligibleTier,
|
||||
LoadCodeAssistResponse,
|
||||
OnboardUserRequest,
|
||||
} from './types.js';
|
||||
@@ -35,6 +36,16 @@ export class ValidationCancelledError extends Error {
|
||||
}
|
||||
}
|
||||
|
||||
export class IneligibleTierError extends Error {
|
||||
readonly ineligibleTiers: IneligibleTier[];
|
||||
|
||||
constructor(ineligibleTiers: IneligibleTier[]) {
|
||||
const reasons = ineligibleTiers.map((t) => t.reasonMessage).join(', ');
|
||||
super(reasons);
|
||||
this.ineligibleTiers = ineligibleTiers;
|
||||
}
|
||||
}
|
||||
|
||||
export interface UserData {
|
||||
projectId: string;
|
||||
userTier: UserTierId;
|
||||
@@ -127,13 +138,7 @@ export async function setupUser(
|
||||
}
|
||||
|
||||
// If user is not setup for standard tier, inform them about all other tiers they are ineligible for.
|
||||
if (loadRes.ineligibleTiers && loadRes.ineligibleTiers.length > 0) {
|
||||
const reasons = loadRes.ineligibleTiers
|
||||
.map((t) => t.reasonMessage)
|
||||
.join(', ');
|
||||
throw new Error(reasons);
|
||||
}
|
||||
throw new ProjectIdRequiredError();
|
||||
throwIneligibleOrProjectIdError(loadRes);
|
||||
}
|
||||
return {
|
||||
projectId: loadRes.cloudaicompanionProject,
|
||||
@@ -180,7 +185,8 @@ export async function setupUser(
|
||||
userTierName: tier.name,
|
||||
};
|
||||
}
|
||||
throw new ProjectIdRequiredError();
|
||||
|
||||
throwIneligibleOrProjectIdError(loadRes);
|
||||
}
|
||||
|
||||
return {
|
||||
@@ -190,6 +196,13 @@ export async function setupUser(
|
||||
};
|
||||
}
|
||||
|
||||
function throwIneligibleOrProjectIdError(res: LoadCodeAssistResponse): never {
|
||||
if (res.ineligibleTiers && res.ineligibleTiers.length > 0) {
|
||||
throw new IneligibleTierError(res.ineligibleTiers);
|
||||
}
|
||||
throw new ProjectIdRequiredError();
|
||||
}
|
||||
|
||||
function getOnboardTier(res: LoadCodeAssistResponse): GeminiUserTier {
|
||||
for (const tier of res.allowedTiers || []) {
|
||||
if (tier.isDefault) {
|
||||
|
||||
Reference in New Issue
Block a user