Skip to content

Commit

Permalink
object:refactor data encode error
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Kejie Zhang <[email protected]>
  • Loading branch information
kjzz committed Sep 5, 2018
1 parent 78a32f2 commit 47c4dcb
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions core/commands/object/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ import (
cid "gx/ipfs/QmZFbDTY9jfSBms2MchvYM9oYRbAF19K7Pby47yDBfpPrb/go-cid"
)

// ErrObjectTooLarge is returned when too much data was read from stdin. current limit 2m
var ErrObjectTooLarge = errors.New("input object was too large. limit is 2mbytes")

const inputLimit = 2 << 20

type Node struct {
Expand All @@ -43,6 +40,12 @@ type Object struct {
Links []Link `json:"Links,omitempty"`
}

var (
// ErrObjectTooLarge is returned when too much data was read from stdin. current limit 2m
ErrObjectTooLarge = errors.New("input object was too large. limit is 2mbytes")
ErrDataEncoding = errors.New("unkown data field encoding")
)

var ObjectCmd = &cmds.Command{
Helptext: cmdkit.HelpText{
Tagline: "Interact with IPFS objects.",
Expand Down Expand Up @@ -575,7 +578,7 @@ func deserializeNode(nd *Node, dataFieldEncoding string) (*dag.ProtoNode, error)
}
dagnode.SetData(data)
default:
return nil, fmt.Errorf("unkown data field encoding")
return nil, ErrDataEncoding
}

links := make([]*ipld.Link, len(nd.Links))
Expand Down Expand Up @@ -617,5 +620,5 @@ func encodeData(data []byte, encoding string) (string, error) {
return base64.StdEncoding.EncodeToString(data), nil
}

return "", fmt.Errorf("unkown data field encoding")
return "", ErrDataEncoding
}

0 comments on commit 47c4dcb

Please sign in to comment.