Go "cannot convert" Type Errors - Fix Conversions in CI
Go could not convert a value from one type to another. The conversion is invalid - the types are not convertible, the constant overflows the target, or a named type and a different one cannot be cast directly.
What this error means
The build stops with cannot convert X (type A) to type B, pointing at the conversion. It is deterministic and names both types, often after a refactor or a dependency that changed a type.
./convert.go:9:14: cannot convert s (variable of type []string) to type string
# or
./convert.go:14:9: cannot convert 300 (untyped int constant) to type uint8Common causes
The two types are not convertible
Go only allows conversions between compatible types (numeric to numeric, named type to its underlying type, etc.). Converting a slice to a string or unrelated structs is invalid.
A constant that overflows the target type
Converting an untyped constant whose value does not fit (e.g. 300 into a uint8) is rejected at compile time.
A wrong cast after an API change
A dependency changed a field or return type, so an existing explicit conversion no longer matches the value’s type.
How to fix it
Convert through the correct operation
Use the right conversion for the types - e.g. parse/serialize rather than a raw cast, or a byte-slice round-trip for strings.
// []byte <-> string is a valid conversion:
b := []byte("hello")
s := string(b)
// for []string -> string, join instead of converting:
s = strings.Join(parts, ",")Keep constants within the target range
- Read the target type’s range from the error.
- Use a value that fits, or a wider type that can hold it.
- For runtime values, check bounds before converting.
Reconcile with a changed dependency type
When an upgrade changed a type, update the conversion (or the surrounding code) to match the new type.
How to prevent it
- Convert only between genuinely compatible types; parse/serialize otherwise.
- Keep constant values within the target type’s range.
- Pin dependencies and read changelogs so type changes do not surprise call sites.