{"id":47179767,"url":"https://github.com/dgca/result","last_synced_at":"2026-03-13T07:34:41.113Z","repository":{"id":340306554,"uuid":"1165343404","full_name":"dgca/result","owner":"dgca","description":"Utility function for better error handling","archived":false,"fork":false,"pushed_at":"2026-02-24T07:16:18.000Z","size":53,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-02-24T13:37:51.663Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dgca.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-02-24T04:17:56.000Z","updated_at":"2026-02-24T07:16:23.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/dgca/result","commit_stats":null,"previous_names":["dgca/result"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/dgca/result","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dgca%2Fresult","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dgca%2Fresult/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dgca%2Fresult/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dgca%2Fresult/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dgca","download_url":"https://codeload.github.com/dgca/result/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dgca%2Fresult/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30460949,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-13T06:34:02.089Z","status":"ssl_error","status_checked_at":"2026-03-13T06:33:49.182Z","response_time":60,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: 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-03-13T07:34:40.685Z","updated_at":"2026-03-13T07:34:41.093Z","avatar_url":"https://github.com/dgca.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @dgca/result\n\nA tiny utility for cleaner error handling in TypeScript. Wraps a function call and returns a `{ data, error }` tuple instead of throwing.\n\n## Install\n\n```bash\npnpm add @dgca/result\n```\n\n## Usage\n\n### Async\n\n```ts\nimport { result } from \"@dgca/result\";\n\nconst { data, error } = await result(async () =\u003e {\n  const response = await fetch(\"https://api.example.com/data\");\n\n  if (!response.ok) throw new Error(\"Request failed\");\n\n  return response.json();\n});\n\nif (error) {\n  console.error(\"Something went wrong:\", error.message);\n} else {\n  console.log(\"Got data:\", data);\n}\n```\n\n### Sync\n\n```ts\nimport { result } from \"@dgca/result\";\n\nconst { data, error } = result(() =\u003e {\n  return JSON.parse(someString);\n});\n\nif (error) {\n  console.error(\"Invalid JSON:\", error.message);\n} else {\n  console.log(\"Parsed:\", data);\n}\n```\n\n### How it works\n\n- If the function **returns** a value, you get `{ data: value, error: null }`.\n- If the function **throws**, you get `{ data: null, error: Error }`.\n- If something non-Error is thrown (e.g. a string), it gets wrapped in `new Error()`.\n- If the function is async, `result()` returns a `Promise` — just `await` it.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdgca%2Fresult","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdgca%2Fresult","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdgca%2Fresult/lists"}