From fae36b992b457ebcaec6f2089a9a427c039b2deb Mon Sep 17 00:00:00 2001 From: Aaron Date: Tue, 10 Mar 2026 14:38:01 -0400 Subject: [PATCH 1/4] Detect auth/GUID failures early instead of cascading into locale fallback When all GUIDs fail API key retrieval (HTTP 500), bail immediately with a clear error pointing to auth expiry or bad GUIDs. In the locale detection catch block, distinguish between auth problems (keys also failed) and transient issues, and stop silently falling back to en-us. Co-Authored-By: Claude Opus 4.6 --- src/core/auth.ts | 48 +++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 39 insertions(+), 9 deletions(-) diff --git a/src/core/auth.ts b/src/core/auth.ts index 4efc1a4..f1465c8 100644 --- a/src/core/auth.ts +++ b/src/core/auth.ts @@ -399,6 +399,7 @@ export class Auth { // Step 3: Get API keys for all GUIDs const allGuids = [...state.sourceGuid, ...state.targetGuid]; state.apiKeys = []; + const failedGuids: string[] = []; for (const guid of allGuids) { if (guid) { @@ -408,11 +409,23 @@ export class Auth { state.apiKeys.push({ guid, previewKey, fetchKey }); } catch (error) { + failedGuids.push(guid); console.log(ansiColors.yellow(`Warning: Could not get keys for GUID ${guid}: ${error.message}`)); } } } + // If ALL GUIDs failed key retrieval, this is almost certainly an auth or GUID problem + const validGuids = allGuids.filter(g => g); + if (validGuids.length > 0 && failedGuids.length === validGuids.length) { + console.log(ansiColors.red(`\nError: Failed to retrieve API keys for all specified GUIDs.`)); + console.log(ansiColors.red(`This usually means either:`)); + console.log(ansiColors.red(` 1. Your authentication has expired — run 'agility auth' to re-authenticate`)); + console.log(ansiColors.red(` 2. The GUID(s) are incorrect — verify your --sourceGuid / --targetGuid values`)); + console.log(ansiColors.red(` 3. Your account does not have access to these instances\n`)); + return false; + } + // Step 4: Set up UI mode in state state.useHeadless = state.headless; // headless takes precedence state.useVerbose = !state.useHeadless && state.verbose; @@ -524,17 +537,34 @@ export class Auth { } catch (error) { - console.log(ansiColors.yellow(`Note: Could not auto-detect locales: ${error.message}`)); - state.availableLocales = ["en-us"]; // Fallback to default - - // Create fallback mapping for all GUIDs - const fallbackLocales = state.locale.length > 0 ? [state.locale[0]] : ["en-us"]; - for (const guid of allGuids) { - if (guid) { - state.guidLocaleMap.set(guid, fallbackLocales); + // If we also failed to get keys for any GUIDs, this is likely an auth/GUID problem — fail fast + if (failedGuids.length > 0) { + console.log(ansiColors.red(`\nError: Unable to retrieve locales, and API key retrieval also failed.`)); + console.log(ansiColors.red(`This strongly indicates an authentication or GUID configuration problem.`)); + console.log(ansiColors.red(` - Run 'agility auth' to re-authenticate`)); + console.log(ansiColors.red(` - Verify your --sourceGuid / --targetGuid values are correct\n`)); + return false; + } + + // Keys succeeded but locales failed — could be a transient issue, fall back gracefully + console.log(ansiColors.yellow(`Warning: Could not auto-detect locales: ${error.message}`)); + if (state.locale.length > 0) { + // User specified locales explicitly, use those + const guidLocaleMap = new Map(); + for (const guid of allGuids) { + if (guid) { + guidLocaleMap.set(guid, state.locale); + } } + state.guidLocaleMap = guidLocaleMap; + state.availableLocales = state.locale; + console.log(`📝 Using user-specified locales: ${state.locale.join(", ")}`); + } else { + // No explicit locales and auto-detect failed — can't safely assume en-us + console.log(ansiColors.red(`Error: Could not detect available locales and no --locale flag was provided.`)); + console.log(ansiColors.red(`Please specify locales explicitly with --locale (e.g., --locale en-us)\n`)); + return false; } - console.log(`📝 Using fallback mapping: all GUIDs → ${fallbackLocales.join(", ")}`); } } From 5a544314ae4ed988afbeda94673c2c927c4775f6 Mon Sep 17 00:00:00 2001 From: Aaron Date: Tue, 10 Mar 2026 14:51:43 -0400 Subject: [PATCH 2/4] correcting llm commands --- src/core/auth.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/auth.ts b/src/core/auth.ts index f1465c8..429e86c 100644 --- a/src/core/auth.ts +++ b/src/core/auth.ts @@ -420,7 +420,7 @@ export class Auth { if (validGuids.length > 0 && failedGuids.length === validGuids.length) { console.log(ansiColors.red(`\nError: Failed to retrieve API keys for all specified GUIDs.`)); console.log(ansiColors.red(`This usually means either:`)); - console.log(ansiColors.red(` 1. Your authentication has expired — run 'agility auth' to re-authenticate`)); + console.log(ansiColors.red(` 1. Your authentication has expired — run 'agility login' to re-authenticate`)); console.log(ansiColors.red(` 2. The GUID(s) are incorrect — verify your --sourceGuid / --targetGuid values`)); console.log(ansiColors.red(` 3. Your account does not have access to these instances\n`)); return false; @@ -541,7 +541,7 @@ export class Auth { if (failedGuids.length > 0) { console.log(ansiColors.red(`\nError: Unable to retrieve locales, and API key retrieval also failed.`)); console.log(ansiColors.red(`This strongly indicates an authentication or GUID configuration problem.`)); - console.log(ansiColors.red(` - Run 'agility auth' to re-authenticate`)); + console.log(ansiColors.red(` - Run 'agility login' to re-authenticate`)); console.log(ansiColors.red(` - Verify your --sourceGuid / --targetGuid values are correct\n`)); return false; } From 8257873f58ad63ff3ef26e91c577277a45a133d2 Mon Sep 17 00:00:00 2001 From: Aaron Date: Tue, 10 Mar 2026 15:04:46 -0400 Subject: [PATCH 3/4] fail fast if we fail ANY key retrieval --- src/core/auth.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/core/auth.ts b/src/core/auth.ts index 429e86c..62b6569 100644 --- a/src/core/auth.ts +++ b/src/core/auth.ts @@ -415,9 +415,8 @@ export class Auth { } } - // If ALL GUIDs failed key retrieval, this is almost certainly an auth or GUID problem - const validGuids = allGuids.filter(g => g); - if (validGuids.length > 0 && failedGuids.length === validGuids.length) { + // If any GUIDs failed key retrieval, this is almost certainly an auth or GUID problem + if (failedGuids.length > 0) { console.log(ansiColors.red(`\nError: Failed to retrieve API keys for all specified GUIDs.`)); console.log(ansiColors.red(`This usually means either:`)); console.log(ansiColors.red(` 1. Your authentication has expired — run 'agility login' to re-authenticate`)); @@ -538,6 +537,7 @@ export class Auth { } catch (error) { // If we also failed to get keys for any GUIDs, this is likely an auth/GUID problem — fail fast + // This should never happen, but just in case if (failedGuids.length > 0) { console.log(ansiColors.red(`\nError: Unable to retrieve locales, and API key retrieval also failed.`)); console.log(ansiColors.red(`This strongly indicates an authentication or GUID configuration problem.`)); From 8a6105f4efba1862d80b937bbfc8d3214e6bd12d Mon Sep 17 00:00:00 2001 From: Aaron Date: Tue, 10 Mar 2026 15:08:54 -0400 Subject: [PATCH 4/4] Cleaning up output --- src/core/auth.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/core/auth.ts b/src/core/auth.ts index 62b6569..acacd80 100644 --- a/src/core/auth.ts +++ b/src/core/auth.ts @@ -410,14 +410,13 @@ export class Auth { state.apiKeys.push({ guid, previewKey, fetchKey }); } catch (error) { failedGuids.push(guid); - console.log(ansiColors.yellow(`Warning: Could not get keys for GUID ${guid}: ${error.message}`)); } } } // If any GUIDs failed key retrieval, this is almost certainly an auth or GUID problem if (failedGuids.length > 0) { - console.log(ansiColors.red(`\nError: Failed to retrieve API keys for all specified GUIDs.`)); + console.log(ansiColors.red(`\nError: Failed to retrieve API keys for one or more specified GUIDs.`)); console.log(ansiColors.red(`This usually means either:`)); console.log(ansiColors.red(` 1. Your authentication has expired — run 'agility login' to re-authenticate`)); console.log(ansiColors.red(` 2. The GUID(s) are incorrect — verify your --sourceGuid / --targetGuid values`)); @@ -539,7 +538,7 @@ export class Auth { // If we also failed to get keys for any GUIDs, this is likely an auth/GUID problem — fail fast // This should never happen, but just in case if (failedGuids.length > 0) { - console.log(ansiColors.red(`\nError: Unable to retrieve locales, and API key retrieval also failed.`)); + console.log(ansiColors.red(`Error: Unable to retrieve locales, and API key retrieval also failed.`)); console.log(ansiColors.red(`This strongly indicates an authentication or GUID configuration problem.`)); console.log(ansiColors.red(` - Run 'agility login' to re-authenticate`)); console.log(ansiColors.red(` - Verify your --sourceGuid / --targetGuid values are correct\n`));