hcengineering/platform · error

Type and value are required

Error message

Type and value are required

What it means

SocialIdMongoDbCollection.insertOne validates that a social identity document carries both `type` and `value` before persisting. These two fields are the minimum data needed to build the composite `key` via buildSocialIdString, which uniquely identifies the social ID. If either is undefined (omitted or explicitly set to undefined), the collection refuses the insert and throws.

Source

Thrown at server/account/src/collections/mongo.ts:256

    return res.map((acc: Account) => this.convertToObj(acc))
  }

  async findOne (query: Query<Account>): Promise<Account | null> {
    const res = await this.collection.findOne<Account>(getFilteredQuery(query) as Filter<Account>)

    return res !== null ? this.convertToObj(res) : null
  }
}

export class SocialIdMongoDbCollection extends MongoDbCollection<SocialId, '_id'> implements DbCollection<SocialId> {
  constructor (db: Db) {
    super('socialId', db, '_id')
  }

  async insertOne (data: Partial<SocialId>): Promise<any> {
    if (data.type === undefined || data.value === undefined) {
      throw new Error('Type and value are required')
    }

    return await super.insertOne({
      ...data,
      key: buildSocialIdString(data as SocialKey)
    })
  }
}

export class WorkspaceStatusMongoDbCollection implements DbCollection<WorkspaceStatus> {
  constructor (private readonly wsCollection: MongoDbCollection<WorkspaceInfoWithStatus, 'uuid'>) {}

  private toWsQuery (query: Query<WorkspaceStatus>): Query<WorkspaceInfoWithStatus> {
    const res: Query<WorkspaceInfoWithStatus> = {}

    for (const key of Object.keys(getFilteredQuery(query))) {
      const qVal = (query as any)[key]
      if (key === 'workspaceUuid') {

View on GitHub (pinned to 63e28dc964)

Solutions

  1. Ensure the object passed to insertOne contains both `type` and `value` before calling; validate at the caller/service layer.
  2. If data comes from an external provider, check that provider name and profile identifier are present before creating the SocialId document.
  3. Confirm you are not shadowing or renaming fields — the collection checks literal keys `type` and `value`, not alternates like `provider` or `id`.
  4. Wrap the call in try/catch and surface a 400-style validation error to the client instead of a 500.

Example fix

// before
await socialId.insertOne({ personUuid, value: socialValue })
// after
if (socialType === undefined || socialValue === undefined) {
  throw new Error('social id type and value are required')
}
await socialId.insertOne({ personUuid, type: socialType, value: socialValue })
Defensive patterns

Strategy: validation

Validate before calling

function canInsertSocialId(data) {
  return data !== null && typeof data === 'object' && data.type !== undefined && data.value !== undefined
}
if (!canInsertSocialId(input)) throw new Error('social id requires type and value')

Type guard

function isSocialIdInput(d: Partial<SocialId> | undefined | null): d is Pick<SocialId, 'type' | 'value'> & Partial<SocialId> {
  return d !== undefined && d !== null && (d as any).type !== undefined && (d as any).value !== undefined
}

Try / catch

try {
  await socialId.insertOne(data)
} catch (err) {
  if (err instanceof Error && err.message === 'Type and value are required') {
    throw new BadRequestError('Social ID must include type and value')
  }
  throw err
}

Prevention

When it happens

Trigger: Calling socialId.insertOne with a Partial<SocialId> missing `type` (e.g. { value: 'github-user-1' }), missing `value` (e.g. { type: 'github' }), or both (e.g. { personUuid: '...' } or an empty object). Explicitly passing `type: undefined` also triggers it.

Common situations: Building the social-ID object dynamically from optional OAuth-provider payload fields (provider name or profile id missing); a refactor that renamed `type`/`value` so the old keys no longer populate; deserializing JSON where the fields were dropped; accidentally passing a user record instead of a social-ID record.

Understand the failure class

Background: "Missing required field" and "field is required" errors: why libraries reject payloads that omit mandatory fields — this error's family across 20 libraries.

Related errors


AI-assisted analysis of hcengineering/platform@63e28dc964 (2026-08-29). Data as JSON: /api/errors/4dbeea9470700148. Report an issue: GitHub.