{"id":30596114,"url":"https://github.com/joshi4/uerrors","last_synced_at":"2025-08-29T21:15:43.524Z","repository":{"id":151965929,"uuid":"75258929","full_name":"joshi4/uerrors","owner":"joshi4","description":"go package to couple log friendly error messages with user friendly ones. ","archived":false,"fork":false,"pushed_at":"2016-12-01T06:23:34.000Z","size":3,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-08-24T17:47:05.639Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/joshi4.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}},"created_at":"2016-12-01T05:36:09.000Z","updated_at":"2016-12-02T09:41:41.000Z","dependencies_parsed_at":"2023-06-02T10:15:09.739Z","dependency_job_id":null,"html_url":"https://github.com/joshi4/uerrors","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/joshi4/uerrors","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joshi4%2Fuerrors","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joshi4%2Fuerrors/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joshi4%2Fuerrors/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joshi4%2Fuerrors/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/joshi4","download_url":"https://codeload.github.com/joshi4/uerrors/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joshi4%2Fuerrors/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":272765602,"owners_count":24989397,"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","status":"online","status_checked_at":"2025-08-29T02:00:10.610Z","response_time":87,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":"2025-08-29T21:15:38.881Z","updated_at":"2025-08-29T21:15:43.519Z","avatar_url":"https://github.com/joshi4.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"#uerrors \n\nInternal error messages are usually brief and in a format that is optimized for logging and searching. \n\nAn example would be: \n\n~~~sh\n\u003e error=true, service=phantom, txid=12345, msg=\"user not authorized\"\n~~~ \n\nWhile that's a great error message for developers to search by tags, its not a great error message to display to an end user.\n\nUsually, there's a translation layer that would take this error message and then return a more user friendly message to the end user. It might look something like: \n\n~~~go \nswitch err:\n  case ErrInvalidUser:\n    umsg := \"You are not authorized to perform this action\"\n  default: \n    umsg := err.Error()\n// send umsg down in a response body along with an appropriate statsCode \n~~~\n\n\nIt's often hard to find all the code paths and errors an API request could create and then individually, add them to a swtich statement. \n\nThis is where `uerrors` comes in. It offers an easy interface to attach a user-friendly message while creating the original error itself.  \n\n## Usage \n\nTo create a New uerror \n\n~~~go \n\nerr := uerrors.New(\"pkg: invalid token\", \"Please renew your API token\")\n~~~ \n\n\nTo create an uerror with values available only at run time: \n\n~~~go \n\nerr := uerrors.FromErrors(fmt.Errorf(\"pkg: txnid=%s, resource=%s\", txnid,resource), \n                          fmt.Errorf(\"Your API request to %s failed. Please contact support if the issue persists\", resource)) \n~~~ \n\n\n## Constructing an user friendly response: \n\n~~~go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"io\"\n\t\"log\"\n\t\"net/http\"\n\n\t\"github.com/joshi4/uerrors\"\n)\n\nfunc main() {\n\thttp.HandleFunc(\"/feature\", serveFeature)\n\thttp.HandleFunc(\"/\", serveIndex)\n\thttp.ListenAndServe(\":6060\", nil)\n}\n\nfunc serveIndex(w http.ResponseWriter, req *http.Request) {\n\tuerr := uerrors.New(\"example: redirect failed\", \"Please visit http://localhost:6060/feature if you aren't redirected automatically\")\n\tlog.Println(uerr.Error())\n\tio.WriteString(w, uerr.UserError())\n}\n\nfunc serveFeature(w http.ResponseWriter, req *http.Request) {\n\tpath := req.URL.Path\n\tuerr := uerrors.FromErrors(fmt.Errorf(\"example: error=true, endpoint=%s\", path),\n\t\tfmt.Errorf(\"Please visit %s a little later\", path))\n\tlog.Println(uerr.Error())\n\tio.WriteString(w, uerr.UserError())\n}\n~~~\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoshi4%2Fuerrors","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjoshi4%2Fuerrors","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoshi4%2Fuerrors/lists"}