{"record":{"id":"c745747a2f28d9db","repo":"CherryHQ/cherry-studio","slug":"feishu-registration-begin-failed-json-stringify","errorCode":null,"errorMessage":"Feishu registration begin failed: ${JSON.stringify(res)}","messagePattern":"Feishu registration begin failed: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/main/ai/channels/adapters/feishu/FeishuAppRegistration.ts","lineNumber":74,"sourceCode":"  const baseUrl = BASE_URLS[domain]\n\n  // Step 1: init — check supported auth methods\n  const initRes = await postRegistration(baseUrl, { action: 'init' })\n  logger.info('Feishu registration init response', { supported: initRes })\n\n  // Step 2: begin — start device flow\n  const res = await postRegistration(baseUrl, {\n    action: 'begin',\n    archetype: 'PersonalAgent',\n    auth_method: 'client_secret',\n    request_user_info: 'open_id'\n  })\n\n  const deviceCode = res.device_code as string | undefined\n  const verificationUri = res.verification_uri_complete as string | undefined\n\n  if (!deviceCode || !verificationUri) {\n    throw new Error(`Feishu registration begin failed: ${JSON.stringify(res)}`)\n  }\n\n  return {\n    deviceCode,\n    verificationUri,\n    interval: (res.interval as number) ?? 5,\n    expiresIn: (res.expires_in as number) ?? 600\n  }\n}\n\nexport async function registrationPoll(\n  domain: FeishuDomain,\n  deviceCode: string,\n  options: { interval: number; expiresIn: number; signal?: AbortSignal }\n): Promise<RegistrationResult> {\n  const baseUrl = BASE_URLS[domain]\n  const deadline = Date.now() + options.expiresIn * 1000\n  let interval = options.interval * 1000","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/CherryHQ/cherry-studio/blob/726446b54cd69ffe51a276638672f6d95ca0768c/src/main/ai/channels/adapters/feishu/FeishuAppRegistration.ts#L56-L92","documentation":"Thrown by registrationBegin() when the 'begin' action response lacks device_code or verification_uri_complete. These two fields are required to drive the device/QR flow; their absence means the device-flow start did not actually begin.","triggerScenarios":"postRegistration with action:'begin', archetype:'PersonalAgent', auth_method:'client_secret' returns a JSON object missing device_code and/or verification_uri_complete. The full response is JSON.stringify-d into the message.","commonSituations":"Feishu changed the device-flow response schema, the archetype/auth_method values are rejected, the registration endpoint returned an inline error object instead of throwing, or the domain's API surface doesn't support this flow.","solutions":["Inspect the embedded JSON — look for an error/error_description field that explains the rejection.","Confirm archetype:'PersonalAgent' and auth_method:'client_secret' are still the accepted values for the target domain.","Verify the chosen FeishuDomain has a working registration endpoint (BASE_URLS entry).","Retry once; if the schema change is real, update the field extraction to match the new response."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Validate the begin response shape before relying on it.\nfunction hasDeviceFlowFields(res: unknown): res is { device_code: string; verification_uri_complete: string } {\n  return typeof res === 'object' && res !== null\n    && typeof (res as any).device_code === 'string'\n    && typeof (res as any).verification_uri_complete === 'string'\n}","typeGuard":"function isFeishuBeginFailed(e: unknown): e is Error {\n  return e instanceof Error && e.message.startsWith('Feishu registration begin failed:')\n}","tryCatchPattern":"try {\n  const { deviceCode, verificationUri } = await registrationBegin(domain)\n  showQr(verificationUri)\n} catch (e) {\n  if (isFeishuBeginFailed(e)) { notifyUser('Could not start Feishu registration; retry later'); return }\n  throw e\n}","preventionTips":["Confirm archetype/auth_method values are still accepted for the target domain.","Inspect the embedded JSON for an inline error explaining the rejection.","Retry begin once; if the schema changed, update field extraction."],"tags":["feishu","registration","device-flow","schema","validation"],"backgroundTag":null,"analyzedSha":"726446b54cd69ffe51a276638672f6d95ca0768c","analyzedAt":"2026-08-12T17:30:37.448Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}