cockroachdb/cockroach · error
could not parse query (expected PKG.TEST): %s
Error message
could not parse query (expected PKG.TEST): %s
What it means
Raised by parseQuery (testowner.go:162-169) in its github-prefixed branch. The query began with `github.com/cockroachdb/cockroach/`, but strings.IndexByte found no '.' after that prefix (dotIdx == -1) or found one immediately after it (dotIdx == 0, i.e. an empty package), so the string cannot be split at the first post-prefix dot into a package and a test name. The tool signals this by panicking, so the process dies with a stack trace and non-zero exit. Both the single-argument mode (line 148) and each stdin line (line 137) run through this parse.
Source
Thrown at pkg/cmd/testowner/testowner.go:168
writeOwners(stdout, teams)
for _, log := range logs {
fmt.Fprintln(stderr, log)
}
} else {
fmt.Fprintf(stderr, "usage: `testowner PKG.TEST` or `testowner` (with queries in stdin); got %d arguments, expected 0-1\n", len(flag.Args()))
return 1
}
}
return 0
}
func parseQuery(pkgAndTest string) (pkg string, test string) {
const githubPrefix = "github.com/cockroachdb/cockroach/"
var dotIdx int
if strings.HasPrefix(pkgAndTest, githubPrefix) {
dotIdx = strings.IndexByte(pkgAndTest[len(githubPrefix):], '.')
if dotIdx <= 0 {
panic(fmt.Sprintf("could not parse query (expected PKG.TEST): %s", pkgAndTest))
}
dotIdx += len(githubPrefix)
} else {
dotIdx = strings.IndexByte(pkgAndTest, '.')
if dotIdx <= 0 {
panic(fmt.Sprintf("could not parse query (expected PKG.TEST): %s", pkgAndTest))
}
}
pkg, test = pkgAndTest[:dotIdx], pkgAndTest[dotIdx+1:]
return
}
func writeOwners(w io.Writer, teams []team.Team) {
var prev bool
if len(teams) == 0 {
panic("empty team slice")
}
for _, team := range teams {View on GitHub (pinned to 8812064a01)
Solutions
- Append the test name to form a full query: `testowner github.com/cockroachdb/cockroach/pkg/cmd/dev.TestDataDriven`
- Or use the equivalent short form without the prefix: `testowner pkg/cmd/dev.TestDataDriven`
- If piping many queries on stdin, generate `PKG.TEST` pairs (e.g. `go test -list '.*' ./pkg/...` output joined with the package) rather than bare package paths
- Filter out blank/whitespace-only lines before feeding stdin (a prefix-only line cannot contain the .TEST part)
Example fix
// before: package import path only, no .TEST suffix after the github prefix $ ./testowner github.com/cockroachdb/cockroach/pkg/cmd/dev panic: could not parse query (expected PKG.TEST): github.com/cockroachdb/cockroach/pkg/cmd/dev // after: full github.com/.../PKG.TEST (or the short form) $ ./testowner github.com/cockroachdb/cockroach/pkg/cmd/dev.TestDataDriven $ ./testowner pkg/cmd/dev.TestDataDriven
Defensive patterns
Strategy: validation
Validate before calling
// Mirrors parseQuery (testowner.go:162-179) without panicking: split at the
// first '.' after the optional github.com/cockroachdb/cockroach/ prefix.
func validateQuery(q string) error {
const prefix = "github.com/cockroachdb/cockroach/"
s := strings.TrimPrefix(q, prefix)
if dot := strings.IndexByte(s, '.'); dot <= 0 {
return fmt.Errorf("query must be PKG.TEST (got %q)", q)
}
return nil
} Try / catch
If you cannot pre-validate (e.g. calling the binary), catch the panic at the process boundary: a non-zero exit with `could not parse query` on stderr means malformed input — log the offending query and continue or abort. If you reuse parseQuery in-process, wrap the call with a deferred recover: `defer func() { if r := recover(); r != nil { /* handle bad query */ } }()`. Prevention
- Always type queries as full PKG.TEST, e.g. github.com/cockroachdb/cockroach/pkg/cmd/dev.TestDataDriven
- Prefer the short form pkg/cmd/dev.TestDataDriven — fewer characters, no prefix to mistype
- Generate stdin input as PKG.TEST pairs (join go list ./... with go test -list output), never bare import paths
- Run validateQuery over each line before piping a batch to testowner
When it happens
Trigger: Invoking `testowner github.com/cockroachdb/cockroach/pkg/cmd/dev` (package import path with the .TEST part forgotten); any github-prefixed string with no '.' after the prefix, e.g. `github.com/cockroachdb/cockroach/`; an empty package like `github.com/cockroachdb/cockroach/.TestFoo`; feeding stdin a list of package paths (from go list ./... or editor copy) instead of PKG.TEST lines.
Common situations: Pasting a package path from go-to-definition / go list output and forgetting to append .TestName; scripts that emit import paths rather than PKG.TEST pairs; a query truncated by shell history editing or a missing test name in a generated input file.
Related errors
- error while processing file %s
- failed parsing datum string as
- cannot set both COCKROACH_FORCE_DEV_VERSION and COCKROACH_TE
- cannot have two files with the same basename in DISTDIR_FILE
- invalid trusted proxy CIDRs
AI-assisted analysis of cockroachdb/cockroach@8812064a01 (2026-08-15).
Data as JSON: /api/errors/a636b766475911c1.
Report an issue: GitHub.