unionlabs/union · error
newValPubKey is not of type crypto.PubKey
Error message
newValPubKey is not of type crypto.PubKey
What it means
getCommandArgs requires appOpts.Get(server.KeyUserPubKey) to be a crypto.PubKey interface value (e.g., an ed25519.PubKey injected by the testnet key generation). A nil value or a non-PubKey type — notably a raw string or []byte from configuration — fails the assertion and panics.
Source
Thrown at uniond/cmd/uniond/cmd/testnet.go:226
panic(err)
}
}
return app
}
// parse the input flags and returns valArgs
func getCommandArgs(appOpts servertypes.AppOptions) (valArgs, error) {
args := valArgs{}
newValAddr, ok := appOpts.Get(server.KeyNewValAddr).(bytes.HexBytes)
if !ok {
panic("newValAddr is not of type bytes.HexBytes")
}
args.newValAddr = newValAddr
newValPubKey, ok := appOpts.Get(server.KeyUserPubKey).(crypto.PubKey)
if !ok {
panic("newValPubKey is not of type crypto.PubKey")
}
args.newValPubKey = newValPubKey
newOperatorAddress, ok := appOpts.Get(server.KeyNewOpAddr).(string)
if !ok {
panic("newOperatorAddress is not of type string")
}
args.newOperatorAddress = newOperatorAddress
upgradeToTrigger, ok := appOpts.Get(server.KeyTriggerTestnetUpgrade).(string)
if !ok {
panic("upgradeToTrigger is not of type string")
}
args.upgradeToTrigger = upgradeToTrigger
// validate and set accounts to fund
accountsString := cast.ToString(appOpts.Get(flagAccountsToFund))
for _, account := range strings.Split(accountsString, ",") {
if account != "" {View on GitHub (pinned to 031785bb6d)
Solutions
- Use the `uniond testnet` CLI path where the generated validator key is inserted as a crypto.PubKey
- When setting options yourself, construct the concrete type first (e.g., ed25519.PubKey{Key: bytes}) before viper.Set
- Convert any string-encoded pubkey at the boundary — never rely on the assertion to accept it
- In forks, return an error naming the missing key instead of panicking
Defensive patterns
Strategy: type-guard
Validate before calling
// The pubkey must be a constructed crypto.PubKey, never a string from config
pubKey := ed25519.PubKey{Key: mustHexDecode(pubKeyHex)}
vpr.Set(server.KeyUserPubKey, pubKey) Type guard
func optPubKey(appOpts servertypes.AppOptions, key string) (crypto.PubKey, bool) {
v, ok := appOpts.Get(key).(crypto.PubKey)
return v, ok
} Prevention
- Convert hex/base64 pubkey strings into crypto.PubKey values at the option boundary
- Run testnet through the CLI where key generation inserts the typed value
- Assert option presence in test setup before building the app
- A nil (missing) option fails the assertion the same way as a wrong type — set defaults explicitly
When it happens
Trigger: Programmatic testnet invocation without the flag wired; supplying the public key as a hex/base64 string in appOpts instead of a constructed crypto.PubKey; flag binding removed by a custom command wrapper.
Common situations: Embedding the testnet runner in tests or tooling; loading options from JSON/viper files where everything deserializes to primitives; refactors that skip server.AddTestnetFlags-style wiring.
Related errors
- newValAddr is not of type bytes.HexBytes
- newOperatorAddress is not of type string
- upgradeToTrigger is not of type string
- error while incrementing period: %w
- error while creating a new delegation period record: %w
AI-assisted analysis of unionlabs/union@031785bb6d (2026-08-16).
Data as JSON: /api/errors/139203ef5ac5dcc9.
Report an issue: GitHub.