Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error style for most errors #4829

Merged
merged 1 commit into from
Mar 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/ipfs/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ environment variable:
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) {
cctx := env.(*oldcmds.Context)
if cctx.Online {
res.SetError(errors.New("init must be run offline only!"), cmdkit.ErrNormal)
res.SetError(errors.New("init must be run offline only"), cmdkit.ErrNormal)
return
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/seccat/seccat.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func main() {

func setupPeer(a args) (peer.ID, pstore.Peerstore, error) {
if a.keybits < 1024 {
return "", nil, errors.New("Bitsize less than 1024 is considered unsafe.")
return "", nil, errors.New("bitsize less than 1024 is considered unsafe")
}

out("generating key pair...")
Expand Down
6 changes: 3 additions & 3 deletions commands/legacy/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,20 +173,20 @@ func convertOptions(req *cmds.Request) error {
if len(str) == 0 {
value = "empty value"
}
return fmt.Errorf("Could not convert %q to type %q (for option %q)",
return fmt.Errorf("could not convert %q to type %q (for option %q)",
value, opt.Type().String(), "-"+k)
}
req.Options[k] = val

} else {
return fmt.Errorf("Option %q should be type %q, but got type %q",
return fmt.Errorf("option %q should be type %q, but got type %q",
k, opt.Type().String(), kind.String())
}
}

for _, name := range opt.Names() {
if _, ok := req.Options[name]; name != k && ok {
return fmt.Errorf("Duplicate command options were provided (%q and %q)",
return fmt.Errorf("duplicate command options were provided (%q and %q)",
k, name)
}
}
Expand Down
4 changes: 2 additions & 2 deletions core/commands/cat.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ var CatCmd = &cmds.Command{

offset, _ := req.Options["offset"].(int)
if offset < 0 {
res.SetError(fmt.Errorf("Cannot specify negative offset."), cmdkit.ErrNormal)
res.SetError(fmt.Errorf("cannot specify negative offset"), cmdkit.ErrNormal)
return
}

Expand All @@ -54,7 +54,7 @@ var CatCmd = &cmds.Command{
return
}
if max < 0 {
res.SetError(fmt.Errorf("Cannot specify negative length."), cmdkit.ErrNormal)
res.SetError(fmt.Errorf("cannot specify negative length"), cmdkit.ErrNormal)
return
}
if !found {
Expand Down
4 changes: 2 additions & 2 deletions core/commands/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ func transformConfig(configRoot string, configName string, transformer config.Tr
func getConfig(r repo.Repo, key string) (*ConfigField, error) {
value, err := r.GetConfigKey(key)
if err != nil {
return nil, fmt.Errorf("Failed to get config value: %q", err)
return nil, fmt.Errorf("failed to get config value: %q", err)
}
return &ConfigField{
Key: key,
Expand Down Expand Up @@ -392,7 +392,7 @@ func replaceConfig(r repo.Repo, file io.Reader) error {

keyF, err := getConfig(r, config.PrivKeySelector)
if err != nil {
return fmt.Errorf("Failed to get PrivKey")
return fmt.Errorf("failed to get PrivKey")
}

pkstr, ok := keyF.Value.(string)
Expand Down
2 changes: 1 addition & 1 deletion core/commands/dht.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ var findProvidersDhtCmd = &cmds.Command{
return
}
if numProviders < 1 {
res.SetError(fmt.Errorf("Number of providers must be greater than 0"), cmdkit.ErrNormal)
res.SetError(fmt.Errorf("number of providers must be greater than 0"), cmdkit.ErrNormal)
return
}

Expand Down
2 changes: 1 addition & 1 deletion core/commands/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"gx/ipfs/QmfAkMSt9Fwzk48QDJecPcwCUjnf2uG7MLnmCGTp4C6ouL/go-ipfs-cmds"
)

var ErrInvalidCompressionLevel = errors.New("Compression level must be between 1 and 9")
var ErrInvalidCompressionLevel = errors.New("compression level must be between 1 and 9")

var GetCmd = &cmds.Command{
Helptext: cmdkit.HelpText{
Expand Down
2 changes: 1 addition & 1 deletion core/commands/id.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ EXAMPLE:

func printPeer(ps pstore.Peerstore, p peer.ID) (interface{}, error) {
if p == "" {
return nil, errors.New("Attempted to print nil peer!")
return nil, errors.New("attempted to print nil peer")
}

info := new(IdOutput)
Expand Down
2 changes: 1 addition & 1 deletion core/commands/object/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ func deserializeNode(nd *Node, dataFieldEncoding string) (*dag.ProtoNode, error)
}
dagnode.SetData(data)
default:
return nil, fmt.Errorf("Unkown data field encoding")
return nil, fmt.Errorf("unkown data field encoding")
}

links := make([]*ipld.Link, len(nd.Links))
Expand Down
4 changes: 2 additions & 2 deletions core/commands/pin.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ Example:
switch typeStr {
case "all", "direct", "indirect", "recursive":
default:
err = fmt.Errorf("Invalid type '%s', must be one of {direct, indirect, recursive, all}", typeStr)
err = fmt.Errorf("invalid type '%s', must be one of {direct, indirect, recursive, all}", typeStr)
res.SetError(err, cmdkit.ErrClient)
return
}
Expand Down Expand Up @@ -447,7 +447,7 @@ var verifyPinCmd = &cmds.Command{
quiet, _, _ := res.Request().Option("quiet").Bool()

if verbose && quiet {
res.SetError(fmt.Errorf("The --verbose and --quiet options can not be used at the same time"), cmdkit.ErrNormal)
res.SetError(fmt.Errorf("the --verbose and --quiet options can not be used at the same time"), cmdkit.ErrNormal)
}

opts := pinVerifyOpts{
Expand Down
2 changes: 1 addition & 1 deletion core/commands/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"gx/ipfs/QmceUdzxkimdYsgtX733uNgzf1DLHyBKN6ehGSp85ayppM/go-ipfs-cmdkit"
)

var errNotOnline = errors.New("This command must be run in online mode. Try running 'ipfs daemon' first.")
var errNotOnline = errors.New("this command must be run in online mode. Try running 'ipfs daemon' first")

var PublishCmd = &cmds.Command{
Helptext: cmdkit.HelpText{
Expand Down
4 changes: 2 additions & 2 deletions core/commands/pubsub.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ This command outputs data in the following encodings:
}

if n.Floodsub == nil {
res.SetError(fmt.Errorf("experimental pubsub feature not enabled. Run daemon with --enable-pubsub-experiment to use."), cmdkit.ErrNormal)
res.SetError(fmt.Errorf("experimental pubsub feature not enabled. Run daemon with --enable-pubsub-experiment to use"), cmdkit.ErrNormal)
return
}

Expand Down Expand Up @@ -323,7 +323,7 @@ To use, the daemon must be run with '--enable-pubsub-experiment'.
}

if n.Floodsub == nil {
res.SetError(fmt.Errorf("experimental pubsub feature not enabled. Run daemon with --enable-pubsub-experiment to use."), cmdkit.ErrNormal)
res.SetError(fmt.Errorf("experimental pubsub feature not enabled. Run daemon with --enable-pubsub-experiment to use"), cmdkit.ErrNormal)
return
}

Expand Down
4 changes: 2 additions & 2 deletions core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,7 @@ func (n *IpfsNode) GetKey(name string) (ic.PrivKey, error) {

func (n *IpfsNode) LoadPrivateKey() error {
if n.Identity == "" || n.Peerstore == nil {
return errors.New("loaded private key out of order.")
return errors.New("loaded private key out of order")
}

if n.PrivateKey != nil {
Expand Down Expand Up @@ -826,7 +826,7 @@ func listenAddresses(cfg *config.Config) ([]ma.Multiaddr, error) {
for _, addr := range cfg.Addresses.Swarm {
maddr, err := ma.NewMultiaddr(addr)
if err != nil {
return nil, fmt.Errorf("Failure to parse config.Addresses.Swarm: %s", cfg.Addresses.Swarm)
return nil, fmt.Errorf("failure to parse config.Addresses.Swarm: %s", cfg.Addresses.Swarm)
}
listen = append(listen, maddr)
}
Expand Down
2 changes: 1 addition & 1 deletion core/coreapi/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ func deserializeNode(nd *Node, dataFieldEncoding string) (*dag.ProtoNode, error)
}
dagnode.SetData(data)
default:
return nil, fmt.Errorf("Unkown data field encoding")
return nil, fmt.Errorf("unkown data field encoding")
}

links := make([]*ipld.Link, len(nd.Links))
Expand Down
2 changes: 1 addition & 1 deletion core/corerepo/gc.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (

var log = logging.Logger("corerepo")

var ErrMaxStorageExceeded = errors.New("Maximum storage limit exceeded. Maybe unpin some files?")
var ErrMaxStorageExceeded = errors.New("maximum storage limit exceeded. Try to unpin some files")

type GC struct {
Node *core.IpfsNode
Expand Down
4 changes: 2 additions & 2 deletions exchange/bitswap/testnet/virtual.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (n *network) SendMessage(

receiver, ok := n.clients[to]
if !ok {
return errors.New("Cannot locate peer on network")
return errors.New("cannot locate peer on network")
}

// nb: terminate the context since the context wouldn't actually be passed
Expand All @@ -107,7 +107,7 @@ func (n *network) SendMessage(
func (n *network) deliver(
r bsnet.Receiver, from peer.ID, message bsmsg.BitSwapMessage) error {
if message == nil || from == "" {
return errors.New("Invalid input")
return errors.New("invalid input")
}

n.delay.Wait()
Expand Down
2 changes: 1 addition & 1 deletion exchange/reprovide/reprovide.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (rp *Reprovider) Run(tick time.Duration) {
func (rp *Reprovider) Reprovide() error {
keychan, err := rp.keyProvider(rp.ctx)
if err != nil {
return fmt.Errorf("Failed to get key chan: %s", err)
return fmt.Errorf("failed to get key chan: %s", err)
}
for c := range keychan {
// hash security
Expand Down
2 changes: 1 addition & 1 deletion fuse/ipns/ipns_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ func (dir *Directory) Rename(ctx context.Context, req *fuse.RenameRequest, newDi
return fuse.EPERM
default:
log.Error("Unknown node type for rename target dir!")
return errors.New("Unknown fs node type!")
return errors.New("unknown fs node type")
}
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion fuse/mount/fuse.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (m *mount) mount() error {
// wait for the mount process to be done, or timed out.
select {
case <-time.After(MountTimeout):
return fmt.Errorf("Mounting %s timed out.", m.MountPoint())
return fmt.Errorf("mounting %s timed out", m.MountPoint())
case err := <-errs:
return err
case <-m.fuseConn.Ready:
Expand Down
2 changes: 1 addition & 1 deletion fuse/mount/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func ForceUnmountManyTimes(m Mount, attempts int) error {

<-time.After(time.Millisecond * 500)
}
return fmt.Errorf("Unmount %s failed after 10 seconds of trying.", m.MountPoint())
return fmt.Errorf("unmount %s failed after 10 seconds of trying", m.MountPoint())
}

type closer struct {
Expand Down
2 changes: 1 addition & 1 deletion fuse/readonly/ipfs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ func TestIpfsStressRead(t *testing.T) {
}

if !bytes.Equal(rbuf, data) {
errs <- errors.New("Incorrect Read!")
errs <- errors.New("incorrect read")
}
}
}()
Expand Down
2 changes: 1 addition & 1 deletion fuse/readonly/readonly_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func (s *Node) Attr(ctx context.Context, a *fuse.Attr) error {
a.Mode = 0777 | os.ModeSymlink
a.Size = uint64(len(s.cached.GetData()))
default:
return fmt.Errorf("Invalid data type - %s", s.cached.GetType())
return fmt.Errorf("invalid data type - %s", s.cached.GetType())
}
return nil
}
Expand Down
4 changes: 2 additions & 2 deletions importer/balanced/balanced_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@ func TestTwoChunks(t *testing.T) {

func arrComp(a, b []byte) error {
if len(a) != len(b) {
return fmt.Errorf("Arrays differ in length. %d != %d", len(a), len(b))
return fmt.Errorf("arrays differ in length. %d != %d", len(a), len(b))
}
for i, v := range a {
if v != b[i] {
return fmt.Errorf("Arrays differ at index: %d", i)
return fmt.Errorf("arrays differ at index: %d", i)
}
}
return nil
Expand Down
4 changes: 2 additions & 2 deletions importer/trickle/trickle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,11 @@ func testBuilderConsistency(t *testing.T, rawLeaves UseRawLeaves) {

func arrComp(a, b []byte) error {
if len(a) != len(b) {
return fmt.Errorf("Arrays differ in length. %d != %d", len(a), len(b))
return fmt.Errorf("arrays differ in length. %d != %d", len(a), len(b))
}
for i, v := range a {
if v != b[i] {
return fmt.Errorf("Arrays differ at index: %d", i)
return fmt.Errorf("arrays differ at index: %d", i)
}
}
return nil
Expand Down
2 changes: 1 addition & 1 deletion importer/trickle/trickledag.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ func verifyTDagRec(n ipld.Node, depth int, p VerifyParams) error {
}

if pbn.GetType() != ft.TRaw {
return errors.New("Expected raw block")
return errors.New("expected raw block")
}

if p.RawLeaves {
Expand Down
2 changes: 1 addition & 1 deletion keystore/keystore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ func assertDirContents(dir string, exp []string) error {
}

if len(finfos) != len(exp) {
return fmt.Errorf("Expected %d directory entries", len(exp))
return fmt.Errorf("expected %d directory entries", len(exp))
}

var names []string
Expand Down
10 changes: 5 additions & 5 deletions merkledag/coding.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
func (n *ProtoNode) unmarshal(encoded []byte) error {
var pbn pb.PBNode
if err := pbn.Unmarshal(encoded); err != nil {
return fmt.Errorf("Unmarshal failed. %v", err)
return fmt.Errorf("unmarshal failed. %v", err)
}

pbnl := pbn.GetLinks()
Expand All @@ -30,7 +30,7 @@ func (n *ProtoNode) unmarshal(encoded []byte) error {
n.links[i] = &ipld.Link{Name: l.GetName(), Size: l.GetTsize()}
c, err := cid.Cast(l.GetHash())
if err != nil {
return fmt.Errorf("Link hash #%d is not valid multihash. %v", i, err)
return fmt.Errorf("link hash #%d is not valid multihash. %v", i, err)
}
n.links[i].Cid = c
}
Expand All @@ -47,7 +47,7 @@ func (n *ProtoNode) Marshal() ([]byte, error) {
pbn := n.getPBNode()
data, err := pbn.Marshal()
if err != nil {
return data, fmt.Errorf("Marshal failed. %v", err)
return data, fmt.Errorf("marshal failed. %v", err)
}
return data, nil
}
Expand Down Expand Up @@ -123,9 +123,9 @@ func DecodeProtobufBlock(b blocks.Block) (ipld.Node, error) {
decnd, err := DecodeProtobuf(b.RawData())
if err != nil {
if strings.Contains(err.Error(), "Unmarshal failed") {
return nil, fmt.Errorf("The block referred to by '%s' was not a valid merkledag node", c)
return nil, fmt.Errorf("the block referred to by '%s' was not a valid merkledag node", c)
}
return nil, fmt.Errorf("Failed to decode Protocol Buffers: %v", err)
return nil, fmt.Errorf("failed to decode Protocol Buffers: %v", err)
}

decnd.cached = c
Expand Down
2 changes: 1 addition & 1 deletion merkledag/merkledag.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (n *dagService) Get(ctx context.Context, c *cid.Cid) (ipld.Node, error) {
if err == bserv.ErrNotFound {
return nil, ipld.ErrNotFound
}
return nil, fmt.Errorf("Failed to get block for %s: %v", c, err)
return nil, fmt.Errorf("failed to get block for %s: %v", c, err)
}

return ipld.Decode(b)
Expand Down
2 changes: 1 addition & 1 deletion merkledag/merkledag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ func runBatchFetchTest(t *testing.T, read io.Reader) {
}

if !bytes.Equal(datagot, expected) {
errs <- errors.New("Got bad data back!")
errs <- errors.New("got bad data back")
}
}(i)
}
Expand Down
Loading