canopy-network/canopy · error · Error

Could not find types.proto descriptor

Error message

Could not find types.proto descriptor

What it means

The generate-descriptors.cjs build script compiles the proto directory into a consolidated descriptor set via protobufjs, then splits it back into per-file descriptors. It expects the compiled set to contain a file named exactly 'types.proto' (the name protobufjs consolidates under). If no descriptor file with that name is present in descriptorSet.file, the script throws this error, because the split step cannot proceed without it.

Source

Thrown at plugin/typescript/scripts/generate-descriptors.cjs:86

        const enumMatches = content.matchAll(/^enum\s+(\w+)\s*\{/gm);
        
        fileTypes[protoFile] = {
            messages: [...messageMatches].map(m => m[1]),
            enums: [...enumMatches].map(m => m[1]),
        };
    }
    
    // Find the consolidated types.proto descriptor
    let typesDescriptor = null;
    for (const file of descriptorSet.file) {
        if (file.name === 'types.proto') {
            typesDescriptor = file;
            break;
        }
    }
    
    if (!typesDescriptor) {
        throw new Error('Could not find types.proto descriptor');
    }
    
    // Create individual file descriptors by cloning and filtering
    for (const protoFile of protoFiles) {
        const types = fileTypes[protoFile];
        
        // Clone the descriptor and filter to only include types from this file
        const fileDesc = {
            name: protoFile,
            package: typesDescriptor.package,
            dependency: [],
            messageType: [],
            enumType: [],
            syntax: typesDescriptor.syntax,
            options: typesDescriptor.options,
        };
        
        // Add google/protobuf/any.proto dependency if needed

View on GitHub (pinned to ee8197d91d)

Solutions

  1. Re-run the full proto pipeline in order: `npm run build:proto` then `npm run build:descriptors` (or `make build-all`), so the descriptor set is regenerated fresh and contains the consolidated types.proto.
  2. Verify the descriptor-compilation step in generate-descriptors.cjs actually loads all proto files from proto/ and check the descriptorSet.file names it produces (log them) to confirm whether 'types.proto' is missing or renamed.
  3. If you renamed/moved types.proto in the proto directory, restore it or update the `file.name === 'types.proto'` lookup in the script to match the new name.
  4. Clean stale build artifacts (generated index.js, descriptors output, intermediate descriptor set) and rebuild from a clean checkout.

Example fix

// before (script looks only for types.proto)
for (const file of descriptorSet.file) {
    if (file.name === 'types.proto') { typesDescriptor = file; break; }
}
// after (log available names to diagnose, fall back to first descriptor)
console.log('descriptor files:', descriptorSet.file.map(f => f.name));
for (const file of descriptorSet.file) {
    if (file.name === 'types.proto') { typesDescriptor = file; break; }
}
Defensive patterns

Strategy: validation

Validate before calling

const names = descriptorSet.file.map(f => f.name);
if (!names.includes('types.proto')) {
  throw new Error(`types.proto missing from descriptor set; got: ${names.join(', ')}`);
}

Type guard

function hasTypesDescriptor(set) {
  return Array.isArray(set?.file) && set.file.some(f => f?.name === 'types.proto');
}

Try / catch

try {
  buildDescriptors(descriptorSet);
} catch (err) {
  if (err.message.includes('Could not find types.proto')) {
    console.error('Descriptor set malformed; re-run `npm run build:proto` first.', err.message);
    process.exit(1);
  }
  throw err;
}

Prevention

When it happens

Trigger: Running `npm run build:descriptors` (or `make build-descriptors`) after the proto compilation step produced a descriptor set without a 'types.proto' entry — e.g. the pbjs/proto loader output was generated differently, the proto dir contents changed, or a stale/partial descriptor-set file is passed in.

Common situations: Re-running the descriptor build with a custom proto directory that renames types.proto; regenerating descriptors after editing the script's compilation step; using a different protobufjs version whose output file naming differs; a corrupted or outdated intermediate descriptor file left from a previous build.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of canopy-network/canopy@ee8197d91d (2026-09-06). Data as JSON: /api/errors/ff5a03e8855e7898. Report an issue: GitHub.