Skip to content

Commit

Permalink
profile: change error message to print string representation of wire …
Browse files Browse the repository at this point in the history
…type (google#514)

The proto write type code stored in buffer stores unprintable values
(e.g. 2 when unmarshalling). The desired output when printing an error
message is the string representation of the integer (i.e. strconv.Itoa),
instead of the current behavior string(int) or string(rune), which
return the utf8 literal corresponding to the integer.

As pointed out by @ianlancetaylor in
google@4ac0da8#commitcomment-37524728, commit
4ac0da8 preserves the previous incorrect behavior to pass a vet check,
whereas this change prints the desired output.

Updates golang/go#32479.
  • Loading branch information
smasher164 authored and Gabriel Marin committed Dec 17, 2020
1 parent bb1520e commit 8a02313
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions profile/proto.go
Expand Up @@ -33,7 +33,10 @@

package profile

import "errors"
import (
"errors"
"fmt"
)

type buffer struct {
field int // field tag
Expand Down Expand Up @@ -235,7 +238,7 @@ func decodeField(b *buffer, data []byte) ([]byte, error) {
b.u64 = uint64(le32(data[:4]))
data = data[4:]
default:
return nil, errors.New("unknown wire type: " + string(rune(b.typ)))
return nil, fmt.Errorf("unknown wire type: %d", b.typ)
}

return data, nil
Expand Down

0 comments on commit 8a02313

Please sign in to comment.