Skip to content

Commit

Permalink
fix error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
yihuang committed Oct 23, 2023
1 parent 9c220f5 commit c74ba3b
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions types/chain_id.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@ const ChainIDFieldName = "chain_id"
// TODO consider [encoding/json/v2](https://github.com/golang/go/discussions/63397) when it's ready.
func ParseChainIDFromGenesis(reader io.Reader) (string, error) {
decoder := jstream.NewDecoder(reader, 1).EmitKV()
var chain_id string
var (
chain_id string
ok bool
)
err := decoder.Decode(func(mv *jstream.MetaValue) bool {
if kv, ok := mv.Value.(jstream.KV); ok {
if kv.Key == ChainIDFieldName {
chain_id, _ = kv.Value.(string)
chain_id, ok = kv.Value.(string)

Check warning

Code scanning / CodeQL

Useless assignment to local variable Warning

This definition of ok is never used.
return false
}
}
Expand All @@ -27,6 +30,9 @@ func ParseChainIDFromGenesis(reader io.Reader) (string, error) {
if len(chain_id) > 0 {
return chain_id, nil
}
if !ok {
return "", errors.New("chain-id is not a string")
}
if err == nil {
return "", errors.New("chain-id not found in genesis file")
}
Expand Down

0 comments on commit c74ba3b

Please sign in to comment.