{"record":{"id":"e28ba2451c22fe1b","repo":"yikart/AiToEarn","slug":"responsecode-channelaccountcreaterequiredfieldmiss","errorCode":"ResponseCode.ChannelAccountCreateRequiredFieldMissing","errorMessage":"ChannelAccountCreateRequiredFieldMissing","messagePattern":"ChannelAccountCreateRequiredFieldMissing","errorType":"validation","errorClass":"AppException","httpStatus":null,"severity":"error","filePath":"project/aitoearn-backend/apps/aitoearn-server/src/core/channels/accounts/account.service.ts","lineNumber":467,"sourceCode":"    return account\n  }\n\n  private async emitAccountConnected(userId: string, account: Account): Promise<void> {\n    await this.eventStream.emit(\n      EventStream.Channels,\n      EventTopic.ChannelsAccountConnected,\n      { userId, accountId: account.id, platform: account.type },\n      { source: 'account-service' },\n    )\n  }\n\n  private async normalizeCreateInput(data: AccountCreateInput): Promise<NormalizedAccountCreateInput> {\n    if (data.type === AccountType.WeChatChannels) {\n      return this.normalizeWeChatChannelsCreateInput(data)\n    }\n\n    if (!data.uid || !data.nickname) {\n      throw new AppException(ResponseCode.ChannelAccountCreateRequiredFieldMissing, {\n        fields: [\n          ...(!data.uid ? ['uid'] : []),\n          ...(!data.nickname ? ['nickname'] : []),\n        ],\n      })\n    }\n\n    const normalizedData: NormalizedAccountCreateInput = {\n      ...data,\n      uid: data.uid,\n      nickname: data.nickname,\n    }\n    if (normalizedData.type === AccountType.RedNote && normalizedData.clientType === undefined) {\n      normalizedData.clientType = ClientType.WEB\n    }\n    return normalizedData\n  }\n","sourceCodeStart":449,"sourceCodeEnd":485,"githubUrl":"https://github.com/yikart/AiToEarn/blob/d3aa8bea5b146a8675607cf0144d891aad3e9683/project/aitoearn-backend/apps/aitoearn-server/src/core/channels/accounts/account.service.ts#L449-L485","documentation":"normalizeCreateInput validates generic (non-WeChat-Channels) account creation input. Both uid and nickname are required; if either is missing it throws ChannelAccountCreateRequiredFieldMissing with a data.fields array listing which fields are absent.","triggerScenarios":"POSTing an account create (via createPluginAccount/createRelayAccountRecord path) with type other than WeChatChannels and either data.uid or data.nickname empty/undefined; data.fields in the error tells you which.","commonSituations":"Plugin scraping the social platform failed to capture the profile nickname; client omitting fields in the payload; uid passed as 0/empty string; renamed API fields not updated in the caller.","solutions":["Include both uid and nickname in the create payload (check error data.fields for the missing one).","Fix the plugin/fetch step that produces the profile so it returns a non-empty nickname.","Re-authenticate the platform if uid cannot be resolved from the session.","Send clean non-empty strings — whitespace-only or empty values count as missing."],"exampleFix":"// before\n{ type: 'twitter', uid: '123', nickname: '' }\n// after\n{ type: 'twitter', uid: '123', nickname: 'My Handle' }","handlingStrategy":"validation","validationCode":"const missing = []\nif (!data.uid) missing.push('uid')\nif (!data.nickname) missing.push('nickname')\nif (missing.length) throw new Error(`Missing required fields before create: ${missing.join(', ')}`)","typeGuard":"function hasRequiredAccountFields(d): d is AccountCreateInput & { uid: string; nickname: string } {\n  return typeof d.uid === 'string' && d.uid.length > 0 && typeof d.nickname === 'string' && d.nickname.length > 0\n}","tryCatchPattern":"try {\n  await createAccount(data)\n} catch (e) {\n  if (e instanceof AppException && e.code === ResponseCode.ChannelAccountCreateRequiredFieldMissing) {\n    console.warn('Missing fields:', e.data.fields) // re-prompt user / re-fetch profile\n  } else throw e\n}","preventionTips":["Validate uid and nickname are non-empty strings before the API call.","Fix plugin profile-scraping to always capture a nickname.","Read the error's data.fields array to know exactly what is missing.","Handle empty-string and whitespace-only values as missing."],"tags":["validation","missing-field","channel-account"],"backgroundTag":"required-field-missing","analyzedSha":"d3aa8bea5b146a8675607cf0144d891aad3e9683","analyzedAt":"2026-08-31T14:19:24.185Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}