abhigyanpatwari/GitNexus · error · Error

links[${i}].type "${link.type}" is invalid. Expected: ${VALI

Error message

links[${i}].type "${link.type}" is invalid. Expected: ${VALID_CONTRACT_TYPES.join(', ')}

What it means

Thrown during links[] validation when a link's 'type' field is not one of the allowed contract types. VALID_CONTRACT_TYPES is a closed enum: http, grpc, thrift, topic, lib, custom, include. The message lists all valid values so the fix is mechanical. Note the enum is case-sensitive lowercase.

Source

Thrown at gitnexus/src/core/group/config-parser.ts:75

  if (!raw.name || typeof raw.name !== 'string') throw new Error('name is required in group.yaml');
  if (!raw.repos || typeof raw.repos !== 'object' || Array.isArray(raw.repos)) {
    throw new Error('repos is required in group.yaml (must be a mapping)');
  }

  const repos = raw.repos as Record<string, string>;
  const repoPaths = new Set(Object.keys(repos));

  const rawLinks = (raw.links as unknown[]) || [];
  const links: GroupManifestLink[] = rawLinks.map((l: unknown, i: number) => {
    const link = l as Record<string, unknown>;
    if (!link.from || !repoPaths.has(link.from as string)) {
      throw new Error(`links[${i}].from "${link.from}" does not match any repo path in group`);
    }
    if (!link.to || !repoPaths.has(link.to as string)) {
      throw new Error(`links[${i}].to "${link.to}" does not match any repo path in group`);
    }
    if (!VALID_CONTRACT_TYPES.includes(link.type as ContractType)) {
      throw new Error(
        `links[${i}].type "${link.type}" is invalid. Expected: ${VALID_CONTRACT_TYPES.join(', ')}`,
      );
    }
    if (!VALID_ROLES.includes(link.role as ContractRole)) {
      throw new Error(`links[${i}].role "${link.role}" is invalid. Expected: provider | consumer`);
    }
    if (
      link.contract === undefined ||
      link.contract === null ||
      String(link.contract).trim() === ''
    ) {
      throw new Error(`links[${i}].contract is required`);
    }
    return {
      from: link.from as string,
      to: link.to as string,
      type: link.type as ContractType,
      contract: String(link.contract),

View on GitHub (pinned to d540b00184)

Solutions

  1. Set the link.type to one of: http, grpc, thrift, topic, lib, custom, include (lowercase, exact).
  2. If your contract doesn't fit any of these, use 'custom' as the catch-all.
  3. For C/C++ header includes, use 'include' (and enable detect.includes in the group).

Example fix

# before — wrong case
links:
  - { from: services/api, to: services/worker, type: HTTP, contract: GET /v1, role: provider }

# after
links:
  - { from: services/api, to: services/worker, type: http, contract: GET /v1, role: provider }
Defensive patterns

Strategy: type-guard

Validate before calling

const VALID_CONTRACT_TYPES = ['http','grpc','thrift','topic','lib','custom','include'] as const;
type ContractType = typeof VALID_CONTRACT_TYPES[number];
function isContractType(v: unknown): v is ContractType {
  return typeof v === 'string' && (VALID_CONTRACT_TYPES as readonly string[]).includes(v);
}

Type guard

function isContractType(v: unknown): v is ContractType {
  return typeof v === 'string' && ['http','grpc','thrift','topic','lib','custom','include'].includes(v);
}

Prevention

When it happens

Trigger: A link with type: 'HTTP' (wrong case), type: 'rest', type: 'websocket', or any value outside the seven allowed; a link missing the 'type' field entirely (undefined is not in the enum).

Common situations: Wrong-case typo (HTTP vs http); inventing a contract type not yet supported; copy-paste from docs that used a synonym; missing type field in a hand-authored link.

Related errors


AI-assisted analysis of abhigyanpatwari/GitNexus@d540b00184 (2026-08-12). Data as JSON: /api/errors/d388534f7ce1e79b. Report an issue: GitHub.