grpc-ecosystem/grpc-gateway · error

no such file given: %s

Error message

no such file given: %s

What it means

Registry.LookupFile returns this error when no File with the given name was loaded into the registry's file map. The name must match the proto file name as loaded (typically the path as given to the generator).

Source

Thrown at internal/descriptor/registry.go:410

	if !strings.HasPrefix(location, ".") {
		location = fmt.Sprintf(".%s", location)
	}
	components := strings.Split(location, ".")
	for len(components) > 0 {
		fqen := strings.Join(append(components, name), ".")
		if e, ok := r.enums[fqen]; ok {
			return e, nil
		}
		components = components[:len(components)-1]
	}
	return nil, fmt.Errorf("no enum found: %s", name)
}

// LookupFile looks up a file by name.
func (r *Registry) LookupFile(name string) (*File, error) {
	f, ok := r.files[name]
	if !ok {
		return nil, fmt.Errorf("no such file given: %s", name)
	}
	return f, nil
}

func (r *Registry) GetUseProto3FieldSemantics() bool {
	return r.useProto3FieldSemantics
}

func (r *Registry) SetUseProto3FieldSemantics(useProto3FieldSemantics bool) {
	r.useProto3FieldSemantics = useProto3FieldSemantics
}

// LookupExternalHTTPRules looks up external http rules by fully qualified service method name
func (r *Registry) LookupExternalHTTPRules(qualifiedMethodName string) []*annotations.HttpRule {
	return r.externalHTTPRules[qualifiedMethodName]
}

// AddExternalHTTPRule adds an external http rule for the given fully qualified service method name

View on GitHub (pinned to a58a4436a3)

Solutions

  1. Call registry.LoadFile / Load the target proto before LookupFile
  2. Pass the exact same file path string used when loading
  3. Check case and leading path components of the file name
  4. For custom tooling, iterate registry's files to confirm registered names

Example fix

// before
f, err := reg.LookupFile("example.proto")
// after
err := reg.LoadFile("example/v1/example.proto", reg.NewFile(...))
f, err := reg.LookupFile("example/v1/example.proto")
Defensive patterns

Strategy: try-catch

Validate before calling

func hasFile(reg *Registry, name string) bool {
    _, err := reg.LookupFile(name)
    return err == nil
}

Try / catch

f, err := reg.LookupFile("example/v1/example.proto")
if err != nil {
    return fmt.Errorf("file %s not loaded into registry: %w", name, err)
}

Prevention

When it happens

Trigger: LookupFile(name) called before registry.LoadFile registered that file, or with a name that differs from the loaded file's path/key (e.g. 'a.proto' vs 'proto/example/v1/a.proto').

Common situations: Resolving field paths in tests or tooling before files are loaded; using a normalized/different path form than the one registered; typo in file name.

Understand the failure class

Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.

Related errors


AI-assisted analysis of grpc-ecosystem/grpc-gateway@a58a4436a3 (2026-09-02). Data as JSON: /api/errors/5df35bbf01c198f7. Report an issue: GitHub.