{"id":21595282,"url":"https://github.com/euank/go-errstats","last_synced_at":"2025-04-11T00:10:56.677Z","repository":{"id":66058113,"uuid":"48470632","full_name":"euank/go-errstats","owner":"euank","description":"Go program to print err-check statistics about Go code","archived":false,"fork":false,"pushed_at":"2018-02-01T06:44:43.000Z","size":11,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-24T20:51:12.821Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/euank.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-12-23T05:21:31.000Z","updated_at":"2017-03-30T12:46:25.000Z","dependencies_parsed_at":null,"dependency_job_id":"2d7ac2c0-76bd-4e5b-992c-a098da445150","html_url":"https://github.com/euank/go-errstats","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/euank%2Fgo-errstats","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/euank%2Fgo-errstats/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/euank%2Fgo-errstats/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/euank%2Fgo-errstats/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/euank","download_url":"https://codeload.github.com/euank/go-errstats/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248317709,"owners_count":21083528,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-24T17:35:44.129Z","updated_at":"2025-04-11T00:10:56.669Z","avatar_url":"https://github.com/euank.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# go-errstats\n\n```\n\u003cmontgc\u003e I wonder what percentage of all Go code is \"if err != nil\"\n```\n\nIt's fairly common to hear complaints that Go's error handling is verbose, unwieldy, verbose, and verbose.\nI don't want to get into that argument here, other than to supply data.\n\n## What does this do?\n\nThis is a simple program to parse your Go programs (caveat: will only work if\nyour program already compiles, might not play nice with build flags) and figure\nout what percent of your code is `if err != nil` conditionals.\n\n## What doesn't it work on?\n\nInteresting tidbit, when you do `err := recover(); err != nil`, the type of\n`err` there is `interface{}`, so this program doesn't catch that one.\n\nMost importantly, this program doesn't currently handle compound conditionals (e.g. `if err != nil \u0026\u0026 foo != bar`) and is thus liable to undercount.\n\nIt also doesn't handle build tags nor any other such fancery.\n\nIf you know of other issues or want to fix any of these, issues and pull requests are quite welcome.\n\n##  Sample outputs\n\nI arbitrarily picked a few packages I had lying around to get some sample output:\n\n### Go standard library\n\n```\n$ go version\ngo version go1.8.3 linux/amd64\n$ cd $GOROOT \u0026\u0026 errstats $(go list ./src/... | grep -v \"builtin\")\nStatistics about your go files:\n\tTotal lines: \t674982\n\tTotal meaningful lines: \t429480\n\tTotal expressions: \t2680057\n\tTotal conditionals: \t46280\n\tTotal conditionals that were error checks: \t2824\n\n\tPercent lines that were errchecks: \t0.6575393499115209\n\tPercent expressions that were errchecks: \t0.10537089323100217\n\tPercent conditionals that were errchecks: \t6.101987899740709\n\tPercent of err != nil checks using the var 'err': \t97.06090651558074\n```\n\n### rkt\n\n```\n$ git checkout v1.29.0\n$ errstats $(go list github.com/rkt/rkt/... | grep -v \"^github.com/rkt/rkt/vendor/\")      \nStatistics about your go files:\n\tTotal lines: \t45958\n\tTotal meaningful lines: \t25017\n\tTotal expressions: \t169199\n\tTotal conditionals: \t3837\n\tTotal conditionals that were error checks: \t1923\n\n\tPercent lines that were errchecks: \t7.686772994363833\n\tPercent expressions that were errchecks: \t1.1365315397845142\n\tPercent conditionals that were errchecks: \t50.11727912431587\n\tPercent of err != nil checks using the var 'err': \t98.54394175767031\n```\n\n### Docker\n\n```\n$ git rev-parse --short HEAD\n9b4a616e4b # better known as v18.01.0-ce\n$ errstats $(sort \u003c(go list ./...) \u003c(go list ./vendor/... ./contrib/...) | uniq -u | grep -v \"integration-cli\")\nStatistics about your go files:\n\tTotal lines: \t110203\n\tTotal meaningful lines: \t62945\n\tTotal expressions: \t436162\n\tTotal conditionals: \t10038\n\tTotal conditionals that were error checks: \t4121\n\n\tPercent lines that were errchecks: \t6.546985463499881\n\tPercent expressions that were errchecks: \t0.9448324246495567\n\tPercent conditionals that were errchecks: \t41.053994819685194\n\tPercent of err != nil checks using the var 'err': \t98.9080320310604\n```\n\n## Logrus\n```\n$ git rev-parse --short HEAD\n446d1c1\n$ errstats $(go list github.com/Sirupsen/logrus/...)\nStatistics about your go files:\n  Total lines:  1277\n  Total meaningful lines:   661\n  Total expressions:  4768\n  Total conditionals:   68\n  Total conditionals that were error checks:  9\n\n  Percent lines that were errchecks:  1.361573373676248\n  Percent expressions that were errchecks:  0.18875838926174499\n  Percent conditionals that were errchecks:   13.23529411764706\n  Percent of err != nil checks using the var 'err':   100\n```\n\n## Martini\n```\n$ git rev-parse --short HEAD\n15a4762\n$ errstats $(go list github.com/go-martini/martini/...)\nStatistics about your go files:\n  Total lines:  1088\n  Total meaningful lines:   595\n  Total expressions:  4335\n  Total conditionals:   67\n  Total conditionals that were error checks:  8\n\n  Percent lines that were errchecks:  1.3445378151260505\n  Percent expressions that were errchecks:  0.1845444059976932\n  Percent conditionals that were errchecks:   11.940298507462686\n  Percent of err != nil checks using the var 'err':   100\n```\n\n## http2\n```\n$ git rev-parse --short HEAD\n6c89489\n$ errstats $(go list golang.org/x/net/http2/...)\nStatistics about your go files:\n  Total lines:  8072\n  Total meaningful lines:   4652\n  Total expressions:  29802\n  Total conditionals:   636\n  Total conditionals that were error checks:  79\n\n  Percent lines that were errchecks:  1.6981943250214964\n  Percent expressions that were errchecks:  0.2650828803436011\n  Percent conditionals that were errchecks:   12.421383647798741\n  Percent of err != nil checks using the var 'err':   98.73417721518987\n```\n\n## ecs-agent\n```\n$ git checkout v1.7.0\n$ cat \u003c(. ./scripts/shared_env; errstats $(go list github.com/aws/amazon-ecs-agent/agent/...))\nStatistics about your go files:\n  Total lines:  19539\n  Total meaningful lines:   9346\n  Total expressions:  64451\n  Total conditionals:   807\n  Total conditionals that were error checks:  217\n\n  Percent lines that were errchecks:  2.3218489193237746\n  Percent expressions that were errchecks:  0.33668988844238257\n  Percent conditionals that were errchecks:   26.889714993804215\n  Percent of err != nil checks using the var 'err':   97.6958525345622\n```\n\n## kubernetes\n```\n$ git describe\nv1.9.2\n$ errstats $(go list ./... | grep -v -E \"^k8s.io/kubernetes/test\")\n# can't load package: package k8s.io/kubernetes/staging/src/k8s.io/api/admission/v1beta1: code in directory /home/esk/dev/kgo/src/k8s.io/kubernetes/staging/src/k8s.io/api/admission/v1beta1 expects import \"k8s.io/api/admission/v1beta1\"\n# .... tons of the above\n\nStatistics about your go files:\n\tTotal lines: \t660010\n\tTotal meaningful lines: \t332256\n\tTotal expressions: \t2423393\n\tTotal conditionals: \t40284\n\tTotal conditionals that were error checks: \t11724\n\n\tPercent lines that were errchecks: \t3.528604449581046\n\tPercent expressions that were errchecks: \t0.4837845120457145\n\tPercent conditionals that were errchecks: \t29.103366100685136\n\tPercent of err != nil checks using the var 'err': \t97.77379733879222\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feuank%2Fgo-errstats","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feuank%2Fgo-errstats","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feuank%2Fgo-errstats/lists"}