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 (#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
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 Feb 29, 2020
1 parent 4ac0da8 commit 1ebb73c
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions profile/proto.go
Original file line number Diff line number Diff line change
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 1ebb73c

Please sign in to comment.