{"id":16962491,"url":"https://github.com/threeal/errors-cpp","last_synced_at":"2025-04-11T22:12:48.003Z","repository":{"id":176509258,"uuid":"655982237","full_name":"threeal/errors-cpp","owner":"threeal","description":"A C++ package that provides utilities for error handling","archived":false,"fork":false,"pushed_at":"2025-04-09T07:00:44.000Z","size":303,"stargazers_count":2,"open_issues_count":4,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-11T22:12:43.160Z","etag":null,"topics":["cmake","cpp","cpp-library","error","error-handling","errors","library"],"latest_commit_sha":null,"homepage":"https://threeal.github.io/errors-cpp/","language":"C++","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/threeal.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":"2023-06-20T03:05:41.000Z","updated_at":"2025-04-09T07:00:47.000Z","dependencies_parsed_at":null,"dependency_job_id":"6cbe8298-df96-4766-9560-543f31f80dd4","html_url":"https://github.com/threeal/errors-cpp","commit_stats":null,"previous_names":["threeal/cpp","threeal/errors-cpp"],"tags_count":2,"template":false,"template_full_name":"threeal/cpp-starter","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/threeal%2Ferrors-cpp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/threeal%2Ferrors-cpp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/threeal%2Ferrors-cpp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/threeal%2Ferrors-cpp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/threeal","download_url":"https://codeload.github.com/threeal/errors-cpp/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248487684,"owners_count":21112190,"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":["cmake","cpp","cpp-library","error","error-handling","errors","library"],"created_at":"2024-10-13T23:06:54.856Z","updated_at":"2025-04-11T22:12:47.982Z","avatar_url":"https://github.com/threeal.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Errors C++\n\nErrors C++ is a [C++](https://isocpp.org/) package that provides utilities for error handling.\nThis package mainly consists of the `errors::Error` class, representing an object that may contain an error.\n\nThis package serves as an alternative to error handling using [try-catch exceptions](https://en.cppreference.com/w/cpp/language/try_catch), commonly found in C++ code.\nIt facilitates error handling by returning values, following the style of [Go's error handling](https://go.dev/blog/error-handling-and-go).\n\n## Key Features\n\nThis package provides the following key features:\n\n- Error handling in the style of Go  by returning an `errors::Error`.\n- Support for creating errors in the style of [fmtlib](https://github.com/fmtlib/fmt) using `errors::format`.\n- Direct printing of `errors::Error` using C++ streams and fmtlib.\n\n## Integration\n\nTo integrate this package into your C++ project, you can build and install it locally using [CMake](https://cmake.org/):\n\n```sh\ncmake -B build .\ncmake --build build --config Release\ncmake --install build\n```\n\nOnce installed, you can use it in your CMake project as the `Errors` package:\n\n```cmake\nfind_package(Errors 1.0.0 REQUIRED CONFIG)\n\nadd_executable(foo foo.cpp)\ntarget_link_libraries(foo PRIVATE errors::errors)\n```\n\nAlternatively, you can also integrate this package using [CPM.cmake](https://github.com/cpm-cmake/CPM.cmake):\n\n```cmake\ncpmaddpackage(gh:threeal/errors-cpp@1.0.0)\n\nadd_executable(foo foo.cpp)\ntarget_link_libraries(foo PRIVATE errors)\n```\n\n## Usage\n\nThis package contains an `errors::Error` class, which represents an error object.\nFunctions that may produce errors should return this object so that the error can be handled properly.\n\n```cpp\nerrors::Error read_file(const char* filepath);\n\nint main() {\n  const auto err = read_file(filepath);\n  if (err) {\n    // Handle the error.\n  }\n\n  // Continue processing if no error.\n}\n```\n\nFor functions returning `errors::Error`, use `errors::nil` function to signify no error or return an error object created from the `errors::make` function.\n\n```cpp\nerrors::Error read_file(const char* filepath) {\n  std::ifstream file(filepath);\n  if (!file.is_open()) {\n    return errors::make(\"failed to open file\");\n  }\n\n  // Process with no error.\n\n  return errors::nil();\n}\n```\n\nAlternatively, an error object can also be created with a formatted message in the style of fmtlib using `errors::format` function.\n\n```cpp\nif (!file.is_open()) {\n  return errors::format(\"failed to open '{}'\", filepath);\n}\n```\n\nFor more details and examples, refer to the [examples](./examples) directory.\n\n## License\n\nThis project is licensed under the terms of the [MIT License](./LICENSE).\n\nCopyright © 2023-2025 [Alfi Maulana](https://github.com/threeal)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthreeal%2Ferrors-cpp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthreeal%2Ferrors-cpp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthreeal%2Ferrors-cpp/lists"}