grafana/k6 · error
couldn't read protoset: %w
Error message
couldn't read protoset: %w
What it means
grpc.Client.load() opened the protoset file but io.ReadAll failed while reading its bytes (internal/js/modules/k6/grpc/client.go:113). A pure I/O failure after a successful open - the file is present and opened, but its content could not be read to completion. Rare and usually environmental.
Source
Thrown at internal/js/modules/k6/grpc/client.go:113
if c.vu.State() != nil {
return nil, errors.New("load must be called in the init context")
}
initEnv := c.vu.InitEnv()
if initEnv == nil {
return nil, errors.New("missing init environment")
}
absFilePath := initEnv.GetAbsFilePath(protosetPath)
fdsetFile, err := initEnv.FileSystems["file"].Open(absFilePath)
if err != nil {
return nil, fmt.Errorf("couldn't open protoset: %w", err)
}
defer func() { _ = fdsetFile.Close() }()
fdsetBytes, err := io.ReadAll(fdsetFile)
if err != nil {
return nil, fmt.Errorf("couldn't read protoset: %w", err)
}
fdset := &descriptorpb.FileDescriptorSet{}
if err = proto.Unmarshal(fdsetBytes, fdset); err != nil {
return nil, fmt.Errorf("couldn't unmarshal protoset file %s: %w", protosetPath, err)
}
return c.convertToMethodInfo(fdset)
}
// Note: this function was lifted from `lib/options.go`
func decryptPrivateKey(key, password []byte) ([]byte, error) {
block, _ := pem.Decode(key)
if block == nil {
return nil, errors.New("failed to decode PEM key")
}
blockType := block.TypeView on GitHub (pinned to 93accf6570)
Solutions
- Regenerate and redeploy the protoset (it may be truncated or corrupted)
- Ensure nothing rewrites the file while k6 starts
- Move the protoset to local disk next to the script to rule out network storage
Defensive patterns
Strategy: try-catch
Try / catch
try {
client.load('./pb/service.protoset');
} catch (e) {
if (/couldn't read protoset/.test(e.message)) {
throw new Error('protoset unreadable; regenerate it and ensure nothing rewrites it at startup');
}
throw e;
} Prevention
- Generate protosets as part of the build, not at run time
- Keep them immutable once deployed
- Checksum artifacts in CI to catch truncated files
When it happens
Trigger: client.load(path) where the opened file becomes unreadable mid-read: truncated or replaced between open and read, storage or permission errors at read time, or a corrupted archive entry that opens but fails to read.
Common situations: Data files being rewritten concurrently with test startup; flaky container volumes; partially synced/downloaded protoset files.
Related errors
- couldn't open protoset: %w
- couldn't unmarshal protoset file %s: %w
- gRPC exporter endpoint is required
- persisting screenshot: %w
- failed to close file %s: %w
AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15).
Data as JSON: /api/errors/4ec86630071bdc26.
Report an issue: GitHub.