{"id":21260717,"url":"https://github.com/erf/error_or","last_synced_at":"2025-07-11T03:31:37.772Z","repository":{"id":56824448,"uuid":"477371334","full_name":"erf/error_or","owner":"erf","description":"Return a result ErrorOr with either a value T or an error Object.","archived":false,"fork":false,"pushed_at":"2023-12-06T11:23:27.000Z","size":52,"stargazers_count":9,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2023-12-06T12:33:10.061Z","etag":null,"topics":["dart","dart-package","error","error-handling","flutter","flutter-package"],"latest_commit_sha":null,"homepage":"https://pub.dev/packages/error_or","language":"Dart","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/erf.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-04-03T14:47:01.000Z","updated_at":"2023-11-13T12:28:39.000Z","dependencies_parsed_at":"2022-09-01T09:20:40.528Z","dependency_job_id":null,"html_url":"https://github.com/erf/error_or","commit_stats":null,"previous_names":[],"tags_count":0,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/erf%2Ferror_or","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/erf%2Ferror_or/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/erf%2Ferror_or/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/erf%2Ferror_or/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/erf","download_url":"https://codeload.github.com/erf/error_or/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225670654,"owners_count":17505591,"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":["dart","dart-package","error","error-handling","flutter","flutter-package"],"created_at":"2024-11-21T04:20:19.167Z","updated_at":"2024-11-21T04:30:22.140Z","avatar_url":"https://github.com/erf.png","language":"Dart","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ErrorOr\n\nReturn a result `ErrorOr` with either a value `T` or an error `Object`.\n\n## Features\n\nAlternative error handling by wrapping a function that may throw exceptions, in\na function that handle these and returns an `ErrorOr`.\n\nA more explicit way of defining a function which may return an error and avoid \nhaving to try/catch these functions.\n\n`ErrorOr` can be used for both async and synchronous functions.\n\n## API\n\nCreate an `ErrorOr` instance by calling one of its factory constructors `value`\nor `error`.\n\nCheck `hasError` or `hasValue`, before calling `error` or `value`. If either is\ncalled without the proper check, an `ErrorOrTypeError` is thrown.\n\nThe convenient function `ErrorOr.wrap`, does the try/catch logic for you given\na throwing function. It returns a `FutureOr` so can be used for both async and\nsynchronous functions.\n\n## Examples\n\nAsync example\n\n```dart\nFuture\u003cErrorOr\u003cT\u003e\u003e asyncFuncWhichThrowsWrapper() async {\n  try {\n    return ErrorOr.value(await asyncFuncWhichThrows());\n  } catch (e) {\n    return ErrorOr.error(e);\n  }\n}\n\nErrorOr\u003cString\u003e valueOrError = await asyncFuncWhichThrowsWrapper();\nif (valueOrError.hasError) {\n  return valueOrError;\n}\nString value = valueOrError.value;\n```\n\nOr let `ErrorOr.wrap` handle the try/catch logic\n\n```dart\nErrorOr\u003cString\u003e valueOrError = await ErrorOr.wrap(asyncFuncWhichThrows)\nif (valueOrError.hasError) {\n  return valueOrError;\n}\nString value = valueOrError.value;\n```\n\n## Additional information\n\nSee my article [Error handling in Dart and ErrorOr](https://medium.com/@erlendf/error-handling-in-dart-and-erroror-33a04a96d7e9).\n\nThe \"ErrorOr\" is inspired by the SerenityOS [ErrorOr](https://github.com/SerenityOS/serenity/blob/master/AK/Error.h) type.\n\nThe Success/Failure pattern was inspired by [result_type](https://pub.dev/packages/result_type).\n\nI'd like to keep this package minimal, but please get in touch on github if you\nhave suggestions to improvements.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ferf%2Ferror_or","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ferf%2Ferror_or","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ferf%2Ferror_or/lists"}