apache/beam · error
resource.ParseCPUCount: unable to parse %q: %v
Error message
resource.ParseCPUCount: unable to parse %q: %v
What it means
ParseCPUCount converts a string to an unsigned 64-bit CPU count via strconv.ParseUint(v, 10, 64). If the value is not a valid non-negative integer it panics with 'resource.ParseCPUCount: unable to parse %q: %v'.
Source
Thrown at sdks/go/pkg/beam/options/resource/hint.go:259
func (h acceleratorHint) MergeWithOuter(outer Hint) Hint {
return h
}
func (h acceleratorHint) String() string {
return fmt.Sprintf("accelerator=%v", h.value)
}
// ParseCPUCount converts a number in string form into a hint.
// An invalid format will cause ParseCPUCount to panic.
//
// Hints are advisory only and runners may not respect them.
//
// See https://beam.apache.org/documentation/runtime/resource-hints/ for more information about
// resource hints.
func ParseCPUCount(v string) Hint {
b, err := strconv.ParseUint(v, 10, 64)
if err != nil {
panic(fmt.Sprintf("resource.ParseCPUCount: unable to parse %q: %v", v, err))
}
return CPUCount(uint64(b))
}
// CPUCount hints that this scope should be put in a machine with at least this many CPUs or vCPUs.
//
// Hints are advisory only and runners may not respect them.
//
// See https://beam.apache.org/documentation/runtime/resource-hints/ for more information about
// resource hints.
func CPUCount(v uint64) Hint {
return CPUCountHint{value: uint64(v)}
}
type CPUCountHint struct {
value uint64
}
View on GitHub (pinned to 12126d8942)
Solutions
- Supply a plain non-negative decimal integer string, e.g. '4'
- Trim whitespace and remove unit suffixes like 'cores' or 'vCPU'
- Guard with strconv.ParseUint in the caller before constructing the hint
Example fix
// before
resource.ParseCPUCount("-2")
// after
resource.ParseCPUCount("4") Defensive patterns
Strategy: validation
Validate before calling
if n, err := strconv.ParseUint(v, 10, 64); err != nil {
return fmt.Errorf("invalid cpu count %q", v)
} Try / catch
defer func() {
if r := recover(); r != nil {
err = fmt.Errorf("ParseCPUCount rejected value: %v", r)
}
}() Prevention
- Pass non-negative decimal integer strings only
- Remove unit suffixes like 'cores'/'vCPU' before parsing
- Handle unset config by substituting a default before calling ParseCPUCount
When it happens
Trigger: Calling resource.ParseCPUCount with a non-integer, negative number ('-2'), or out-of-range value, or feeding such a value through --resource_hints=cpu_count=<bad>.
Common situations: Passing '4 cores', a negative value, or an empty string from an unset flag/env var into the hint.
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- resource.ParseMinRAM: unable to parse %q: %v
- resource.ParseMaxActiveBundlesPerWorker: unable to parse %q:
- malformed input for decoding: %s
- unparsable resource hint: %q
- unknown resource hint: %v
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/48b46facaeaa6f83.
Report an issue: GitHub.