{"record":{"id":"6f192ea564d14a2b","repo":"diegosouzapw/OmniRoute","slug":"failed-to-list-profiles-error","errorCode":null,"errorMessage":"Failed to list profiles: ${error}","messagePattern":"Failed to list profiles: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/lib/oauth/services/kiro.ts","lineNumber":500,"sourceCode":"      region === \"us-east-1\"\n        ? \"https://codewhisperer.us-east-1.amazonaws.com\"\n        : `https://q.${region}.amazonaws.com`;\n\n    const response = await fetch(endpoint, {\n      method: \"POST\",\n      headers: {\n        Authorization: `Bearer ${accessToken}`,\n        \"Content-Type\": \"application/x-amz-json-1.0\",\n        \"x-amz-target\": \"AmazonCodeWhispererService.ListAvailableProfiles\",\n        Accept: \"application/json\",\n        tokentype: \"API_KEY\",\n      },\n      body: JSON.stringify({ maxResults: 10 }),\n    });\n\n    if (!response.ok) {\n      const error = await response.text();\n      throw new Error(`Failed to list profiles: ${error}`);\n    }\n\n    const data = await response.json();\n    const profiles = Array.isArray(data?.profiles) ? data.profiles : [];\n    const arnOf = (profile: any) => profile?.arn || profile?.profileArn || null;\n    const match =\n      profiles.find((profile: any) => String(arnOf(profile) || \"\").includes(`:${region}:`)) ||\n      profiles[0];\n    return arnOf(match);\n  }\n\n  /**\n   * Normalize a long-lived Kiro/CodeWhisperer API key.\n   */\n  async validateApiKey(apiKey: string, regionInput?: string) {\n    // Default kept OUT of the parameter list: check-public-creds' CRED_KEY_RE matches the\n    // `apiKey:` annotation and flags any string literal in the signature (fn-param FP class).\n    const region = regionInput || \"us-east-1\";","sourceCodeStart":482,"sourceCodeEnd":518,"githubUrl":"https://github.com/diegosouzapw/OmniRoute/blob/a179ffed5bb2e0b883b9ae7214ce8717b2a94c4d/src/lib/oauth/services/kiro.ts#L482-L518","documentation":"KiroService.listAvailableProfiles: the POST to the CodeWhisperer/Q profile-list endpoint (Bearer accessToken, x-amz-target AmazonCodeWhispererService.ListAvailableProfiles) returned non-ok; raw body appended. Means the access token was rejected or profile listing failed upstream — used by validateApiKey to resolve a profileArn.","triggerScenarios":"Thrown at src/lib/oauth/services/kiro.ts:500 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Inspect the appended error for auth (401/403 → stale token) vs server (5xx → retry) causes","Refresh the access token and retry the listing","Verify the region-derived endpoint host matches the token's region","Handle missing profiles gracefully instead of failing the whole API-key validation"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"a179ffed5bb2e0b883b9ae7214ce8717b2a94c4d","analyzedAt":"2026-08-25T18:35:09.898Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}