{"record":{"id":"77759cc06ef3a599","repo":"larksuite/cli","slug":"app-registration-failed-response-missing-device-c","errorCode":null,"errorMessage":"app registration failed: response missing device_code","messagePattern":"app registration failed: response missing device_code","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/auth/app_registration.go","lineNumber":154,"sourceCode":"\t\t}\n\t\tif msg == \"\" {\n\t\t\tmsg = \"Unknown error\"\n\t\t}\n\t\treturn nil, fmt.Errorf(\"app registration failed: %s\", msg)\n\t}\n\n\t// The protocol field is expire_in; accept the legacy expires_in spelling,\n\t// then normalize to protocol defaults.\n\texpiresIn := getInt(data, \"expire_in\", 0)\n\tif expiresIn <= 0 {\n\t\texpiresIn = getInt(data, \"expires_in\", 0)\n\t}\n\texpiresIn = normalizedExpireIn(expiresIn)\n\tinterval := normalizedInterval(getInt(data, \"interval\", 0))\n\n\tdeviceCode := getStr(data, \"device_code\")\n\tif deviceCode == \"\" {\n\t\treturn nil, fmt.Errorf(\"app registration failed: response missing device_code\")\n\t}\n\n\tuserCode := getStr(data, \"user_code\")\n\tverificationUri := getStr(data, \"verification_uri\")\n\tverificationUriComplete := fmt.Sprintf(\"%s/page/cli?user_code=%s\", ep.Open, userCode)\n\n\treturn &AppRegistrationResponse{\n\t\tDeviceCode:              deviceCode,\n\t\tUserCode:                getStr(data, \"user_code\"),\n\t\tVerificationUri:         verificationUri,\n\t\tVerificationUriComplete: verificationUriComplete,\n\t\tExpiresIn:               expiresIn,\n\t\tInterval:                interval,\n\t}, nil\n}\n\n// BuildVerificationURL appends CLI tracking parameters to the verification URL.\nfunc BuildVerificationURL(baseURL, cliVersion string) string {","sourceCodeStart":136,"sourceCodeEnd":172,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/internal/auth/app_registration.go#L136-L172","documentation":"Thrown by RequestAppRegistration at internal/auth/app_registration.go:154 when the begin response parses as JSON, has no error field and status < 400, but the device_code field is missing or empty. Without a device_code the device authorization flow cannot proceed, so the library treats the response as an invalid protocol payload.","triggerScenarios":"A 2xx JSON response from the registration begin endpoint lacking the device_code key — e.g. a protocol change on the server, a partially-implemented mock/stub server, a proxy rewriting the JSON, or a different service version responding at that URL.","commonSituations":"Hitting an environment where the accounts endpoint is served by an API gateway that returns an empty JSON object; running against a regional endpoint with an older/newer protocol; corporate middleboxes stripping response fields; server-side protocol regression.","solutions":["Retry — a transient server bug may have returned a malformed payload.","Confirm you are on the current CLI version so the request matches the server protocol.","Bypass proxies/inspection appliances that may rewrite response JSON.","Verify the accounts registration endpoint directly with curl to inspect the raw JSON body.","If persistent, file a bug with the CLI maintainers including the HTTP status and sanitized response."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":"func isValidRegistrationResponse(r *AppRegistrationResponse) bool {\n    return r != nil && r.DeviceCode != \"\"\n}","typeGuard":"func hasDeviceCode(r *AppRegistrationResponse) bool { return r != nil && r.DeviceCode != \"\" }","tryCatchPattern":"resp, err := RequestAppRegistration(ctx, client, brand, errOut)\nif err != nil {\n    if strings.Contains(err.Error(), \"missing device_code\") {\n        // server protocol problem: retry once, then report to maintainers\n    }\n    return err\n}","preventionTips":["Keep the CLI current to match the server registration protocol.","Avoid proxy/middleboxes that rewrite JSON bodies.","Validate begin responses in staging integrations before production runs."],"tags":["protocol","device-flow","json","validation"],"backgroundTag":"missing-device-code","analyzedSha":"7fd6ef3c07182257ce776cdc5a614e122d5bd4b3","analyzedAt":"2026-09-04T21:17:44.649Z","contentChangedAt":"2026-09-04T21:17:44.649Z","schemaVersion":2},"datasetVersion":"2026-09-12T02:17:10.037Z"}