Giter Club home page Giter Club logo

errcheck's People

Contributors

alexandear avatar amerine avatar benbjohnson avatar cookieo9 avatar coopernurse avatar dmitshur avatar domgreen avatar dominikh avatar dragonsinth avatar dtcaciuc avatar echlebek avatar edwinavalos avatar foubarre avatar isbadawi avatar jcharum avatar kisielk avatar louissobel avatar lukeshu avatar mbyio avatar meteorgan avatar nicks avatar nmiyake avatar oalders avatar rjarry avatar rmohr avatar robfig avatar stephengroat avatar suzmue avatar thehowl avatar zimmski avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

errcheck's Issues

Can't install

Looks like due to the recent domain change.

$ go get github.com/kisielk/errcheck
# code.google.com/p/go.tools/go/gcimporter
go.tools/go/gcimporter/gcimporter.go:817: cannot use val (type "golang.org/x/tools/go/exact".Value) as type "code.google.com/p/go.tools/go/exact".Value in argument to types.NewConst:
    "golang.org/x/tools/go/exact".Value does not implement "code.google.com/p/go.tools/go/exact".Value (wrong type for Kind method)
        have Kind() "golang.org/x/tools/go/exact".Kind
        want Kind() "code.google.com/p/go.tools/go/exact".Kind

Build fail: cannot use exprFn

% go get github.com/kisielk/errcheck

github.com/kisielk/errcheck

errcheck/main.go:196: cannot use exprFn (type func(ast.Expr, types.Type, interface {})) as type func(ast.Expr, types.Type, exact.Value) in field value

% go version
go version devel +58f8a30f5b78 Tue Apr 16 14:20:06 2013 -0700 linux/amd64

% uname -a
Linux Gothmaug 3.9.0-rc6 #1 SMP Mon Apr 8 14:40:41 EDT 2013 x86_64 AMD Phenom(tm) 9950 Quad-Core Processor AuthenticAMD GNU/Linux

Error:failed to check package: could not type check

Hello,
First, many thanks for your tool.
And, just for feedback, I've got some errors while checking some packages (building successfully):
$ errcheck github.com/gwenn/gosqlite
error:failed to check package: could not type check: /home/gwen/Projects/src/github.com/gwenn/gosqlite/cache.go:35:35: undeclared name: Stmt

$ errcheck github.com/gwenn/csvdiff
error:failed to check package: could not type check: /home/gwen/Projects/src/github.com/gwenn/csvdiff/csvdiff.go:274:20: cannot assign hasher (variable of type hash.Hash64) to variable of type Hasher

Regards.

code.google.com\p\go.tools\go\types\exprstring.go:80: x.Slice3 undefined

I can't install on Windows.

C:\Users\Bruno>go get github.com/kisielk/errcheck
# code.google.com/p/go.tools/go/types
dev\go\gopath\src\code.google.com\p\go.tools\go\types\exprstring.go:80: x.Slice3 undefined (type *ast.SliceExpr has no field or method Slice3)
dev\go\gopath\src\code.google.com\p\go.tools\go\types\exprstring.go:82: x.Max undefined (type *ast.SliceExpr has no field or method Max)
dev\go\gopath\src\code.google.com\p\go.tools\go\types\exprstring.go:83: x.Max undefined (type *ast.SliceExpr has no field or method Max)

Please update import to "github.com/dominikh/go-importer"

The import for "honnef.co/go/importer" appears to be failing using go1.3 behind a firewall, presumably because an improper redirect to "github.com/dominikh/go-importer" fails.

Please consider updating the import to use the "github.com/dominikh/go-importer" directly, which is more likely to be online all the time as well.

Thanks for writing errcheck!

could you tell me what benefit on errcheck

i use gometalinter -e .test -e vendor -e pkg ./... with errcheck
it report many report on

error return value not checked 

but i dont know what mean for this warning. How to fix it?

ErrCheck is slow

Why does it take 2 seconds for ErrCheck to run on a small codebase? I wish it could be fast, so I could integrate it with Vim/Syntastic (See vim-syntastic/syntastic#1286) and run the check on every file save :w.

Upstream changes in go.tools/types

This commit changes some things in the types.Info struct.

The following error will fail compilation after trying to go get github.com/kisielk/errcheck:

src/github.com/kisielk/errcheck/lib/errcheck.go:106: unknown types.Info field 'Objects' in struct literal

Error installing with go get

When installing with go get github.com/kisielk/errcheck on Windows7 64 bit I get the following error:

..\..\kisielk\errcheck\internal\errcheck.go:75: unknown loader.Config field 'ImportFromBinary' in struct literal

That is all the output.

Failed to go get - unknown loader.Config field ImportFromBinary

Installation failed with the following message:

go get github.com/kisielk/errcheck
# github.com/kisielk/errcheck/internal
../../code/go/src/github.com/kisielk/errcheck/internal/errcheck.go:91: unknown loader.Config field 'ImportFromBinary' in struct literal

I'm running Go on tip:

go version
go version devel +bc953b2 Tue Oct 6 03:18:17 2015 +0000 darwin/amd64

index out of range by example command in Go 1.1

go list std | grep -v cmd | xargs -n 1 ~/go/bin/errcheck -ignore 'Close|[wW]rite.|Flush|Seek|[rR]ead.'> stdlibcheck
panic: runtime error: index out of range

goroutine 1 [running]:
main.typeCheck(0xc2000acd40, 0x704298, 0x0, 0x0, 0x0, ...)
/home/dlin/go/src/github.com/kisielk/errcheck/main.go:201 +0x1f1
main.checkFiles(0x704298, 0x0, 0x0, 0xc20006aa00, 0xc200065d40, ...)
/home/dlin/go/src/github.com/kisielk/errcheck/main.go:308 +0x36c
main.main()
/home/dlin/go/src/github.com/kisielk/errcheck/main.go:109 +0x2c9

goroutine 2 [runnable]:

Build Error

./errcheck.go:92: undefined: types.TypeAndValue

Flag for checking assignment to the blank identifier

Currently things like

_ = f()
a, _ = g()

where _ is a return of type error are considered to be explicitly ignored. In some cases it would be good to check for those, so errcheck should support a flag that enables this.

defer

Current version report lines like:

defer client.Close()

Surely, error check is missing here, but that's how defer works and how all guidelines recommend to use it. Asking user to replace it with:

defer func(){ _ = client.Close() }()

is probably overkill.

Can't check packages whose imports are not installed

Example from @dominikh:

dominikh@dominikh-pc $ errcheck honnef.co/go/foo1
/home/dominikh/projects/go_projects/src/honnef.co/go/foo1/foo1.go:12:2  Meh()
dominikh@dominikh-pc $ errcheck honnef.co/go/foo2
error:failed to check package: could not type check: /home/dominikh/projects/go_projects/src/honnef.co/go/foo2/foo2.go:4:2: could not import honnef.co/go/foo1 (can't find import: honnef.co/go/foo1)

Support patterns (...) in command line

From http://golang.org/cmd/go/:

An import path is a pattern if it includes one or more "..." wildcards, each of which can match any string, including the empty string and strings containing slashes. Such a pattern expands to all package directories found in the GOPATH trees with names matching the patterns. As a special case, x/... matches x as well as x's subdirectories. For example, net/... expands to net and packages in its subdirectories.

Ignore functions from a particular package

For example, instead of ignoring all of fmt the ability to ignore just the print functions would be nice.

The implementation of the matching is easy, settling on a good UI for specifying the ignores is the hard part.

Errcheck.go line 74

github.com/kisielk/errcheck/internal/errcheck.go:74: unknown loader.Config field 'SourceImports' in struct literal

Sorry for not sending a merge request. I am still trying to figure out how to write code. But go the following error while installing vim-go

ignore defer calls

currently errcheck finds a lot of calls like defer r.Body.Close() or defer db.Close(). Would it be possible to ignore them to make the tool's output more meaningful and get the real problems to better stand out? Thanks!

Support go and defer statements

Not sure how to do this yet, but errcheck should be able to find errors such as:

go f()

and

defer f()

where f() returns an error. Unfortunately when I tried to do this, it seem that go/types doesn't give a type to the call expression which is part of the go or defer statement.

Upstream change in go.tools/types

At least, that is what it looks like:

../../.go/src/github.com/kisielk/errcheck/lib/errcheck.go:105: cannot use tp.callTypes (type map[ast.Expr]types.Type) as type map[ast.Expr]types.TypeAndValue in field value

ignore underscored directories

Directories that begin with underscores (like _workspace) are ignored by most Go tools and the code inside them is not processed. This is used by godeps and other vendoring tools. Running errcheck ./... in a directory will have errcheck running against the code in Godeps/_workspace/src, which is undesirable in general.

Doesn't build with go-1.1

fractal ~/.local/src/github.com/kisielk/errcheck 24085 [:c061276|✔] 
01:20 :) go build
# github.com/kisielk/errcheck
./main.go:201: cannot use fset (type *token.FileSet) as type string in function argument
./main.go:201: cannot use astFiles (type []*ast.File) as type *token.FileSet in function argument
./main.go:255: obj.GetPkg undefined (type types.Object has no field or method GetPkg)
./main.go:267: undefined: types.NamedType
./main.go:269: t.Obj undefined (type types.Type has no field or method Obj)
./main.go:272: undefined: types.Result
./main.go:274: t.Values undefined (type types.Type has no field or method Values)
./main.go:367: cannot use pkg.Path (type func() string) as type string in map index
./main.go:368: cannot use pkg.Path (type func() string) as type string in map index
./main.go:374: invalid operation: pkg != nil && pkg.Complete (mismatched types bool and func() bool)
./main.go:374: too many errors
fractal ~/.local/src/github.com/kisielk/errcheck 24086 [:c061276|✔] 
01:20 :(

Fails checking go/type

This kind of thing was supposed to be solved by the custom importer, but it doesn't seem to help in this particular case:

$ ./errcheck code.google.com/p/go.tools/go/types
error: failed to check package: could not type check: /home/kamil/src/code.google.com/p/go.tools/go/types/universe.go:61:55: cannot pass argument exact.MakeBool(true) (value of type exact.Value) to variable of type exact.Value

Tried it with types.GcImport as well but that returns a different similar error.

errcheck has trouble when GOPATH contains a symlink

It is related to an old issue #45 but I had failed to document the problem properly; here it is:

REPRO

Preparation

mkdir /mnt/foo/src
cd ~
ln -s /mnt/foo/src
# So that ~/src is a symlink to /mnt/foo/src

I don't think putting GOROOT under a symlink is necessary for this bug to reproduce but since that's my setup, exposing this for completeness. The following should take less than 7 minutes to complete;

git clone -b go1.4.2 https://go.googlesource.com/go ~/src/golang
export GOROOT=~/src/golang
cd ~/src/golang/src
./all.bash

The actual issue I suspect is GOPATH containing a symlink:

export GOPATH=~/src/gopath
mkdir $GOPATH
go get github.com/kisielk/errcheck
cd $GOPATH/src/github.com/kisielk/errcheck
errcheck ./...

EXPECTED

Runs fine.

ACTUAL

Instead of running on github.com/kisielk/errcheck, it runs on $GOROOT/src/runtime.

go get -u broken, due to upstream changes?

16:15:56 production] ~ $ go version
go version go1.5.1 darwin/amd64
[16:16:01 production] ~ $ go get -u github.com/kisielk/errcheck
# github.com/kisielk/errcheck/internal/errcheck
code/src/github.com/kisielk/errcheck/internal/errcheck/errcheck.go:233: impossible type switch case: v.pkg.Info.Types[call].Type (type "go/types".Type) cannot have dynamic type *"golang.org/x/tools/go/types".Named (wrong type for Underlying method)
    have Underlying() "golang.org/x/tools/go/types".Type
    want Underlying() "go/types".Type
code/src/github.com/kisielk/errcheck/internal/errcheck/errcheck.go:236: impossible type switch case: v.pkg.Info.Types[call].Type (type "go/types".Type) cannot have dynamic type *"golang.org/x/tools/go/types".Pointer (wrong type for Underlying method)
    have Underlying() "golang.org/x/tools/go/types".Type
    want Underlying() "go/types".Type
code/src/github.com/kisielk/errcheck/internal/errcheck/errcheck.go:239: impossible type switch case: v.pkg.Info.Types[call].Type (type "go/types".Type) cannot have dynamic type *"golang.org/x/tools/go/types".Tuple (wrong type for Underlying method)
    have Underlying() "golang.org/x/tools/go/types".Type
    want Underlying() "go/types".Type
code/src/github.com/kisielk/errcheck/internal/errcheck/errcheck.go:274: impossible type assertion:
    *"golang.org/x/tools/go/types".Builtin does not implement "go/types".Object (wrong type for Parent method)
        have Parent() *"golang.org/x/tools/go/types".Scope
        want Parent() *"go/types".Scope

update note in README.md

Note that errcheck depends on the go/types package which is currently only available in go tip.

I guess in Go 1.1 it works.

Fails if anything uses cgo

This is probably a known limitation, but I couldn't find a ticket for it, so here goes:

errcheck fails if a dependency uses cgo (has import "C").

Additionally, it seems impossible to ignore this lack of "C" via -ignorepkg (or I just don't know how to use the thing).

[0 tv@brute ~/src/2013/errcheck-bug-cgo]$ ls
repro.go
[0 tv@brute ~/src/2013/errcheck-bug-cgo]$ cat repro.go 
package main

import _ "github.com/jmhodges/levigo"

func main() {
}
[0 tv@brute ~/src/2013/errcheck-bug-cgo]$ errcheck .
error:failed to check package: could not type check: repro.go:3:10: could not import github.com/jmhodges/levigo (/home/tv/go/src/github.com/jmhodges/levigo/conv.go:4:8: could not import C (cannot find package "C" in any of:
    /home/tv/src/go/src/pkg/C (from $GOROOT)
    /home/tv/go/src/C (from $GOPATH)))
[1 tv@brute ~/src/2013/errcheck-bug-cgo]$ errcheck -ignorepkg=github.com/jmhodges/levigo .
error:failed to check package: could not type check: repro.go:3:10: could not import github.com/jmhodges/levigo (/home/tv/go/src/github.com/jmhodges/levigo/cache.go:6:8: could not import C (cannot find package "C" in any of:
    /home/tv/src/go/src/pkg/C (from $GOROOT)
    /home/tv/go/src/C (from $GOPATH)))
[1 tv@brute ~/src/2013/errcheck-bug-cgo]$ errcheck -ignorepkg=C .
error:failed to check package: could not type check: repro.go:3:10: could not import github.com/jmhodges/levigo (/home/tv/go/src/github.com/jmhodges/levigo/iterator.go:6:8: could not import C (cannot find package "C" in any of:
    /home/tv/src/go/src/pkg/C (from $GOROOT)
    /home/tv/go/src/C (from $GOPATH)))
[1 tv@brute ~/src/2013/errcheck-bug-cgo]$ 

Support Build Tags

App engine apps are difficult to configure for errcheck, and don't seem to work even when that is done. My GOPATH is set to: /home/mjibson/go:/home/mjibson/go_appengine/goroot. When running errcheck github.com/mjibson/goread/goapp, I get the following error:

error: failed to check package github.com/mjibson/goread/goapp: could not type check: /home/mjibson/go/src/github.com/mjibson/goread/goapp/admin.go:26:6: could not import github.com/MiniProfiler/go/miniprofiler_gae (/home/mjibson/go/src/github.com/MiniProfiler/go/miniprofiler_gae/miniprofiler_gae.go:26:2: could not import github.com/mjibson/appstats (/home/mjibson/go/src/github.com/mjibson/appstats/cost.go:6:2: could not import code.google.com/p/goprotobuf/proto (/home/mjibson/go/src/code.google.com/p/goprotobuf/proto/pointer_unsafe.go:90:42: cannot convert invalid operand to uintptr)))

That file (pointer_unsafe.go), has +build !appengine at the top, which could explain the error. I added this line to lib/util.go, after ctx := build.Default:

ctx.BuildTags = append(ctx.BuildTags, "appengine")

and the error didn't change. Do you have any other suggestions to get this to run?

[feature] Detect panic

Would be nice if this project could detect unhandled panic too or at least say where the code can panic.
So we could recover and the software dosen't crash.

Handle *ast.IndexExp

unhandled expression at /Network/Cluster/home/kamil/go/src/pkg/net/fd_poll_unix.go:301:21: *ast.IndexExpr &{X:startServersOnce Lbrack:57551 Index:k Rbrack:57553}

Question related to ignore syntax

Sorry for the potentially dumb question.

I am trying to ignore a package but cannot seem to find the correct format.

I am running the following command in the someone/somerepo directory

errcheck -asserts -ignorepkg 'github.com/someone/somerepo/fu/bar' ./...

Can't use errcheck with ./...

Before #44, one could use errcheck like other go tools (errcheck . or errcheck ./...):

$ cd $GOPATH/src/github.com/kisielk/errcheck
$ git checkout 125d5c0d507709f2cb85970b145ae03621f6ffe5
$ go run *.go ./...
example/main.go:17:10   recover()     // UNCHECKED
example/main.go:20:15   defer recover() // UNCHECKED
example/main.go:26:3    a()     // UNCHECKED
example/main.go:30:3    b()        // UNCHECKED
example/main.go:35:5    x.a()     // UNCHECKED
example/main.go:40:7    y.t.a()     // UNCHECKED
example/main.go:44:9    m1["a"]()     // UNCHECKED
example/main.go:53:6    go a()    // UNCHECKED
example/main.go:54:9    defer a() // UNCHECKED
lib/errcheck.go:138:16  defer rd.Close()
exit status 1

After #44 :

$ git checkout master
$ git rev-parse --verify HEAD
6523a1db9b999015d645d53a36a450608d6111a2
$ go run *.go ./...
error: failed to check package: could not type check: import "./.": import relative to unknown directory
exit status 2

However, this way still works (fully qualified package name):

$ go run *.go github.com/kisielk/errcheck/...
github.com/kisielk/errcheck/example/main.go:17:10   recover()     // UNCHECKED
github.com/kisielk/errcheck/example/main.go:20:15   defer recover() // UNCHECKED
github.com/kisielk/errcheck/example/main.go:26:3    a()     // UNCHECKED
github.com/kisielk/errcheck/example/main.go:30:3    b()        // UNCHECKED
github.com/kisielk/errcheck/example/main.go:35:5    x.a()     // UNCHECKED
github.com/kisielk/errcheck/example/main.go:40:7    y.t.a()     // UNCHECKED
github.com/kisielk/errcheck/example/main.go:44:9    m1["a"]()     // UNCHECKED
github.com/kisielk/errcheck/example/main.go:53:6    go a()    // UNCHECKED
github.com/kisielk/errcheck/example/main.go:54:9    defer a() // UNCHECKED
exit status 1

Can't `go get` errcheck anymore

$ go get -u github.com/kisielk/errcheck
# github.com/kisielk/errcheck/lib
../../kisielk/errcheck/lib/errcheck.go:138: impossible type switch case: c.pkg.Info.Types[call].Type (type "golang.org/x/tools/go/types".Type) cannot have dynamic type *"code.google.com/p/go.tools/go/types".Named (wrong type for Underlying method)
    have Underlying() "code.google.com/p/go.tools/go/types".Type
    want Underlying() "golang.org/x/tools/go/types".Type
../../kisielk/errcheck/lib/errcheck.go:141: impossible type switch case: c.pkg.Info.Types[call].Type (type "golang.org/x/tools/go/types".Type) cannot have dynamic type *"code.google.com/p/go.tools/go/types".Tuple (wrong type for Underlying method)
    have Underlying() "code.google.com/p/go.tools/go/types".Type
    want Underlying() "golang.org/x/tools/go/types".Type
../../kisielk/errcheck/lib/errcheck.go:168: impossible type assertion:
    *"code.google.com/p/go.tools/go/types".Builtin does not implement "golang.org/x/tools/go/types".Object (wrong type for Parent method)
        have Parent() *"code.google.com/p/go.tools/go/types".Scope
        want Parent() *"golang.org/x/tools/go/types".Scope

Support for github.com/go-errors/errors

Hello,

Thanks for this useful tool, using it everyday. :)
We've started to use go-errors to easily get stacktraces when something goes wrong. It would be nice if errcheck could check for thoses as well.

I'm seeing an isErrorType() function in the code, would changing this be enough to work?
Basically, I would need to match *errors.Error as well as error in the function signatures.

Would it be acceptable to add a flag for additional error types?
Another option would be to check for the error interface rather than the concrete type, but I don't know if that's feasible.

Best

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.