{"record":{"id":"c47ecfded23196b1","repo":"DIYgod/RSSHub","slug":"user-not-found-c47ecf","errorCode":null,"errorMessage":"User not found","messagePattern":"User not found","errorType":"exception","errorClass":"InvalidParameterError","httpStatus":503,"severity":"warning","filePath":"lib/routes/twitter/api/developer-api/api.ts","lineNumber":227,"sourceCode":"    return (response?.data ?? []).map((tweet) => mapTweetToLegacy(tweet, response.includes, cacheMap));\n};\n\nconst getUserData = (id: string) =>\n    cache.tryGet(`twitter-userdata-${id}`, async () => {\n        const client = await getAppClient();\n        const params = {\n            'user.fields': 'profile_image_url,description,verified,url',\n        };\n        const response = id.startsWith('+') ? await client.v2.user(id.slice(1), params) : await client.v2.userByUsername(id, params);\n        return mapUserToLegacy(response?.data) ?? '';\n    });\n\nconst cacheTryGet = async (_id: string, params: Record<string, any> | undefined, operationName: string, func: (id: string, params?: Record<string, any>) => Promise<any>) => {\n    const userData: any = await getUserData(_id);\n    const id = userData?.id_str;\n    if (id === undefined) {\n        cache.set(`twitter-userdata-${_id}`, '', config.cache.contentExpire);\n        throw new InvalidParameterError('User not found');\n    }\n    return cache.tryGet(getTwitterUserCacheKey(id, operationName, params), () => func(id, params), config.cache.routeExpire, false);\n};\n\nconst getUserTimeline = async (id: string, params?: Record<string, any>, options: Record<string, any> = {}) => {\n    const client = await getAppClient();\n    const response = await client.v2.get(`users/${id}/tweets`, {\n        max_results: params?.count ?? 20,\n        expansions: 'author_id,attachments.media_keys,referenced_tweets.id,referenced_tweets.id.author_id',\n        'tweet.fields': 'created_at,entities,conversation_id,referenced_tweets,author_id,in_reply_to_user_id',\n        'user.fields': 'username,name,profile_image_url,description',\n        'media.fields': 'preview_image_url,url,type,width,height,variants',\n        ...options,\n    });\n    return mapTweetResponseToLegacy(response);\n};\n\nconst getUserTweets = (id: string, params?: Record<string, any>) => cacheTryGet(id, params, 'getUserTweets', (id, params = {}) => getUserTimeline(id, params, { exclude: 'replies' }));","sourceCodeStart":209,"sourceCodeEnd":245,"githubUrl":"https://github.com/DIYgod/RSSHub/blob/bed535e0879dc71c5aff6f1e7bd1ac21ede40115/lib/routes/twitter/api/developer-api/api.ts#L209-L245","documentation":"InvalidParameterError from the Twitter developer-API cacheTryGet helper: getUserData returned no `id_str`, so the requested user/username does not resolve on Twitter. The helper also poisons the cache with an empty entry to avoid repeated lookups, then throws.","triggerScenarios":"Calling a developer-API function for an id/username that Twitter returns no data for — `userData.id_str` is undefined on line 224, so line 225 caches `''` and line 226 throws 'User not found'.","commonSituations":"Username typo, suspended/deleted account, handle renamed, or the developer API lacks the lookup scope; the cached empty entry will keep masking it until contentExpire lapses.","solutions":["Verify the handle exists on x.com.","Flush the cache key `twitter-userdata-{id}` to force a fresh lookup if the user was recently restored/renamed.","Confirm the app has `tweet.read` and `users.read` scopes."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"const userData = await getUserData(_id);\nif (userData?.id_str === undefined) throw new InvalidParameterError(`Twitter user not found: ${_id}`);","typeGuard":"const isUserData = (u: unknown): u is { id_str: string } => typeof u === 'object' && u !== null && typeof (u as any).id_str === 'string';","tryCatchPattern":"try { return await cacheTryGet(_id, params, operationName, func); }\ncatch (e) { if (e instanceof InvalidParameterError && /User not found/.test(e.message)) { await cache.set(`twitter-userdata-${_id}`, undefined); /* allow retry after rename */ } throw e; }","preventionTips":["Flush the twitter-userdata cache after restoring/renaming accounts","Validate handle format before lookup","Surface distinct errors for suspended vs unknown"],"tags":["twitter","invalid-parameter","user-not-found","cache","developer-api"],"backgroundTag":null,"analyzedSha":"bed535e0879dc71c5aff6f1e7bd1ac21ede40115","analyzedAt":"2026-08-12T19:29:35.364Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}