{"id":19167509,"url":"https://github.com/tkdeng/go-fix-error-hook","last_synced_at":"2025-05-07T13:41:22.184Z","repository":{"id":257792631,"uuid":"861896255","full_name":"tkdeng/go-fix-error-hook","owner":"tkdeng","description":"A new way of error handling.","archived":false,"fork":false,"pushed_at":"2024-09-23T18:57:35.000Z","size":10,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-19T23:31:50.623Z","etag":null,"topics":["error-handling","error-monitoring","errors","go","golang"],"latest_commit_sha":null,"homepage":"","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/tkdeng.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":"2024-09-23T17:31:48.000Z","updated_at":"2024-09-25T06:25:48.000Z","dependencies_parsed_at":"2024-09-24T06:24:07.257Z","dependency_job_id":"2bfffd91-6840-4a51-b6d1-552db4aaf3b1","html_url":"https://github.com/tkdeng/go-fix-error-hook","commit_stats":null,"previous_names":["tkdeng/go-fix-error-hook"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tkdeng%2Fgo-fix-error-hook","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tkdeng%2Fgo-fix-error-hook/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tkdeng%2Fgo-fix-error-hook/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tkdeng%2Fgo-fix-error-hook/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tkdeng","download_url":"https://codeload.github.com/tkdeng/go-fix-error-hook/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252889083,"owners_count":21820113,"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":["error-handling","error-monitoring","errors","go","golang"],"created_at":"2024-11-09T09:37:57.164Z","updated_at":"2025-05-07T13:41:22.158Z","avatar_url":"https://github.com/tkdeng.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Go Fix Error Hook\n\nA new way of error handling.\n\nBefore throwing an error, you can first attempt to fix it,\nand let any other part of the program try and do something about it.\nThis means if an error is caused by something externally,\na module (for example) could automatically fix the error.\n\n## Installation\n\n```shell\ngo get github.com/tkdeng/go-fix-error-hook\n```\n\n## Usage\n\n```go\n\n// in this example, we will use an \"out of memory\" error\nvar Error_OOM error = errors.New(\"out of memory\")\n\n// example for: fix.Try\nfunc decompress(str string) (string, error) {\n  // do stuff...\n  str, err := \"some large str...\", Error_OOM\n\n  // call before checking for nil error\n  fix.Try(\u0026err, func() error {\n    //note: this method will first run through the fix.Hook list,\n    // and clear the cache (as shown in the `fix.Hook` example).\n\n    // retry stuff...\n    str, err = \"some large string\", nil\n\n    if err != nil {\n      return err // fix failed (try next hook if same error)\n    }\n    return nil // nil = fixed error\n  })\n\n  if err != nil {\n    return \"\", err\n  }\n  return str, nil\n}\n\n// example for: fix.Hook\nvar Cache = map[string]string{}\n\nfunc init(){\n  fix.Hook(Error_OOM, func() bool {\n    // this method will be called, when fix.Try is called.\n    // note: if a previous hook in the list fixes the problem first,\n    // and the error has changed after running the retry callback (in fix.Try),\n    // this method will be skipped.\n\n    if _, ok := Cache[\"old data\"]; !ok { // if \"old data\" not in cache, return false\n      return false // fix changed nothing (skip to next hook)\n    }\n\n    delete(Cache, \"old data\") // remove \"old data\" from cache\n    return true // fix did something (run the retry callback in fix.Try)\n  })\n}\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftkdeng%2Fgo-fix-error-hook","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftkdeng%2Fgo-fix-error-hook","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftkdeng%2Fgo-fix-error-hook/lists"}