{"id":41256563,"url":"https://github.com/0chain/errors","last_synced_at":"2026-01-23T01:51:56.506Z","repository":{"id":46196246,"uuid":"393127599","full_name":"0chain/errors","owner":"0chain","description":null,"archived":false,"fork":false,"pushed_at":"2024-09-10T06:57:27.000Z","size":58,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-09-10T09:13:28.829Z","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":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/0chain.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2021-08-05T17:44:33.000Z","updated_at":"2024-09-10T06:57:31.000Z","dependencies_parsed_at":"2024-06-20T23:27:33.546Z","dependency_job_id":"ebf7c70c-3ab5-42a2-b8c8-421d59719c67","html_url":"https://github.com/0chain/errors","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/0chain/errors","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0chain%2Ferrors","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0chain%2Ferrors/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0chain%2Ferrors/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0chain%2Ferrors/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/0chain","download_url":"https://codeload.github.com/0chain/errors/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0chain%2Ferrors/sbom","scorecard":{"id":263,"data":{"date":"2025-08-11","repo":{"name":"github.com/0chain/errors","commit":"2f10572115f6021f58ddb86a7a2fd79204249c77"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3.8,"checks":[{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Code-Review","score":4,"reason":"Found 5/12 approved changesets -- score normalized to 4","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/backup.yml:1","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/backup.yml:13: update your workflow using https://app.stepsecurity.io/secureworkflow/0chain/errors/backup.yml/main?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/backup.yml:44: update your workflow using https://app.stepsecurity.io/secureworkflow/0chain/errors/backup.yml/main?enable=pin","Warn: pipCommand not pinned by hash: .github/workflows/backup.yml:29","Info:   0 out of   1 GitHub-owned GitHubAction dependencies pinned","Info:   0 out of   1 third-party GitHubAction dependencies pinned","Info:   0 out of   1 pipCommand dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":9,"reason":"license file detected","details":["Info: project has a license file: LICENSE.txt:0","Warn: project license file does not contain an FSF or OSI license."],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'main'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 26 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-14T12:21:23.790Z","repository_id":46196246,"created_at":"2025-08-14T12:21:23.790Z","updated_at":"2025-08-14T12:21:23.790Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28677714,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-23T01:00:35.747Z","status":"ssl_error","status_checked_at":"2026-01-23T01:00:19.529Z","response_time":144,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":"2026-01-23T01:51:55.772Z","updated_at":"2026-01-23T01:51:56.499Z","avatar_url":"https://github.com/0chain.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 0chain/errors\n\nA simple errors package\n\n```\ngo get github.com/0chain/errors\n```\n\nwe introduce a new application error which has errorCode and errorMsg. \n\n```\ntype Error struct {\n\tCode string `json:\"code,omitempty\"`\n\tMsg  string `json:\"msg\"`\n}\n```\n\n## New Error\n\nThen `errors.New` function returns a new error given the code (optional) and msg\n\ntwo arguments can be passed!\n1. code\n2. message\nif only one argument is passed its considered as message\nif two arguments are passed then\n\tfirst argument is considered for code and\n\tsecond argument is considered for message\n\n```\n applicationError := errors.New(\"401\", \"Unauthorized\")\n simpleError = errors.New(\"validation failed\")\n```\n\n\n## Standard error interface implementation\n\nThis is what is printed when you do `.Error()` for the above example\n\n```\nfmt.Println(auth(\"username\", \"password\"))\n\n401: Unauthorized\nvalidation failed\npassword mismatch\n```\n\n## Error propagation\n\nThe `errors.Wrap` function returns a new error that adds context to the original error. You can wrap using a msg or error. For example\n```\nvar ErrPasswordMismatch = errors.New(\"password mismatch\") // \"invalid argument\"\nvar ErrUnAuthorized = errors.New(\"401\", \"Unauthorized\")\n\nfunc auth(username, password string) error {\n    err := validate(username, password)\n    if err != nil {\n        return errors.Wrap(err, ErrUnAuthorized)\n    }\n}\n\n\nfunc validate(username, password string) error {\n    err := passwordValidation(password)\n    if err != nil {\n        return errors.Wrap(err, \"validation failed\")\n    }\n}\n\nfunc passwordValidation(password string) error{\n    // on invalid password\n    return ErrPasswordMismatch\n}\n\n```\n\nThe `errors.UnWrap` function returns the current error and the previous error\n\n```\ncurrent, previous := errors.UnWrap(auth(\"username\", \"password\"))\n\nfmt.Println(current) =\u003e 401: Unauthorized\nfmt.Println(previous) =\u003e validation failed\n                         password mismatch\n\n// futher more\n\ncurrent, previous := errors.UnWrap(previous)\n\nfmt.Println(current) =\u003e validation failed\nfmt.Println(previous) =\u003e password mismatch\n\n// further more\n\ncurrent, previous := errors.UnWrap(previous)\n\nfmt.Println(current) =\u003e password mismatch\nfmt.Println(previous) =\u003e nil\n```\n\nFor retrieving the cause of an error, The `errors.Cause` function is the way to go\n\n```\nerr = auth(\"username\", \"password\")\n\nfmt.Println(errors.Cause(err)) =\u003e password mismatch\n```\n\n## Working with [Errors](https://blog.golang.org/go1.13-errors) package\n\nHow to raise an `ApplicationError` with predefined error variables?\n\n```\nvar ErrInvalidFormat = errors.New(\"[conf]invalid format\")\n\nfunc ReadConfig()  (*Config,error) {\n   //...\n   return nil, Throw(ErrInvalidFormat, cfgFile)\n\n}\n\nfunc main() {\n\ncfg, err := ReadConfig() \n\nif errors.Is(err, ErrInvalidFormat) {\n    panic(err)\n}\n\n}\n\n```\n\nSee [Unit Tests](throw_test.go) for more examples.\n\n\n## Logging and track Unhandled Exception with traceid\n\n### What is an Unhandled Exception?\nAn exception is a known type of error. An unhandled exception occurs when the application code does not properly handle exceptions. \n\nFor example, When you try to read data from database, it is a common problem for the network is lost. We need show user an firendly message (eg. ServiceUnavailable),logging raw error in logging system, and trigger DevOps alert from log monitor system.\n\n\n```\nvar ErrServiceUnavailable = errors.New(\"Service unavailable\")\nif err != nil { //any network/db error\n    if errors.Is(err, ErrHasNotShared) {\n         return nil, err\n    }\n    return nil, errors.ThrowLog(err,ErrServiceUnavailable)\n}\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F0chain%2Ferrors","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F0chain%2Ferrors","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F0chain%2Ferrors/lists"}