{"record":{"id":"0728884916634df7","repo":"decolua/9router","slug":"trae-getloginguidance-failed-lasterr","errorCode":null,"errorMessage":"`Trae GetLoginGuidance failed: ${lastErr}`","messagePattern":"`Trae GetLoginGuidance failed: (.+?)`","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/lib/oauth/providers/trae.js","lineNumber":50,"sourceCode":"        headers: {\n          Accept: \"application/json\",\n          \"Content-Type\": \"application/json\",\n          \"User-Agent\": TRAE_CONFIG.userAgent,\n        },\n        body,\n      });\n      if (!res.ok) { lastErr = `${url} HTTP ${res.status}`; continue; }\n      const data = await res.json();\n      const loginHost = extractJsonPath(data, [\n        [\"Result\", \"LoginHost\"], [\"Result\", \"loginHost\"], [\"Result\", \"LoginURL\"],\n        [\"result\", \"loginHost\"], [\"data\", \"Result\", \"LoginHost\"], [\"data\", \"loginHost\"],\n        [\"LoginHost\"], [\"loginHost\"],\n      ]);\n      if (loginHost) return loginHost;\n      lastErr = `${url} missing LoginHost`;\n    } catch (e) { lastErr = `${url} ${e.message}`; }\n  }\n  throw new Error(`Trae GetLoginGuidance failed: ${lastErr}`);\n}\n\n// Build the browser verification URL the user opens to sign in.\nfunction buildTraeVerificationUrl(loginHost, loginTraceId, callbackUrl, ctx) {\n  const url = new URL(loginHost.startsWith(\"http\") ? loginHost : `https://${loginHost.replace(/^\\/+/, \"\")}`);\n  url.pathname = TRAE_CONFIG.authorizationPath;\n  const p = new URLSearchParams();\n  p.set(\"login_version\", \"1\");\n  p.set(\"auth_from\", \"trae\");\n  p.set(\"login_channel\", \"native_ide\");\n  p.set(\"plugin_version\", ctx.plugin_version);\n  p.set(\"auth_type\", \"local\");\n  p.set(\"client_id\", TRAE_CONFIG.clientId);\n  p.set(\"redirect\", \"0\");\n  p.set(\"login_trace_id\", loginTraceId);\n  p.set(\"auth_callback_url\", callbackUrl);\n  p.set(\"machine_id\", ctx.machine_id);\n  p.set(\"device_id\", ctx.device_id);","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/decolua/9router/blob/90b52e06ffd666b7929554211474d01588f6b1f8/src/lib/oauth/providers/trae.js#L32-L68","documentation":"Thrown by fetchTraeLoginGuidance after it exhausts every candidate URL: each attempt either threw (network/parse failure) or returned a response lacking a LoginHost field, and lastErr records the final failure. Means the Trae login-guidance API never yielded a usable login host, so the browser sign-in URL cannot be built.","triggerScenarios":"All configured guidance URLs fail: Trae API unreachable/DNS failure, endpoint changed shape and no longer returns LoginHost/LoginHost key, 4xx/5xx responses, or a fetch rejection (timeout, TLS).","commonSituations":"Trae changed their GetLoginGuidance response schema after a server update; corporate proxy/DNS blocks the Trae domain; running fully offline; regional endpoint deprecated.","solutions":["Read lastErr in the message: 'missing LoginHost' → the response schema changed, update the key extraction list; otherwise it's a network/HTTP failure.","Verify the Trae guidance endpoint URL is current (check for provider-side API changes) and reachable with curl.","Check DNS/proxy/firewall for the Trae domain if the error is a fetch exception.","Retry later if the Trae API is having an outage."],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"async function traeeReachable(url) {\n  try { const r = await fetch(url, { method: 'HEAD' }); return r.ok; } catch { return false; }\n}","typeGuard":null,"tryCatchPattern":"try {\n  const guidance = await fetchTraeLoginGuidance(ctx);\n} catch (e) {\n  if (e.message.startsWith('Trae GetLoginGuidance failed:')) {\n    // check lastErr: 'missing LoginHost' → schema change; otherwise network — retry or report outage\n  } else throw e;\n}","preventionTips":["Health-check the Trae guidance endpoint before starting login flows.","Pin/verify guidance URLs against current Trae API docs; watch for response schema changes.","Ensure DNS/proxy allows the Trae domains in restricted networks.","Retry with backoff across attempts rather than failing on the first URL."],"tags":["network","api-schema-change","oauth","endpoint-unreachable"],"backgroundTag":"endpoint-unreachable","analyzedSha":"90b52e06ffd666b7929554211474d01588f6b1f8","analyzedAt":"2026-08-30T21:05:45.952Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}