{"id":13484040,"url":"https://github.com/skorks/nesty","last_synced_at":"2025-04-06T08:13:12.058Z","repository":{"id":7913397,"uuid":"9297355","full_name":"skorks/nesty","owner":"skorks","description":"Nested exceptions for Ruby","archived":false,"fork":false,"pushed_at":"2013-05-02T02:29:33.000Z","size":134,"stargazers_count":118,"open_issues_count":1,"forks_count":8,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-30T07:11:15.192Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Ruby","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/skorks.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-04-08T13:38:54.000Z","updated_at":"2025-03-21T07:14:13.000Z","dependencies_parsed_at":"2022-09-08T06:02:10.317Z","dependency_job_id":null,"html_url":"https://github.com/skorks/nesty","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skorks%2Fnesty","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skorks%2Fnesty/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skorks%2Fnesty/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skorks%2Fnesty/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/skorks","download_url":"https://codeload.github.com/skorks/nesty/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247451665,"owners_count":20940944,"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":[],"created_at":"2024-07-31T17:01:18.485Z","updated_at":"2025-04-06T08:13:12.039Z","avatar_url":"https://github.com/skorks.png","language":"Ruby","readme":"[![Build Status](https://travis-ci.org/skorks/nesty.png?branch=master)](https://travis-ci.org/skorks/nesty)\n\n# Nesty\n\nNow, when you rescue an error and then re-raise your own, you don't have to lose track of what actually occured, you can keep/nest the old error in your own and the stacktrace will reflect the cause of the original error.\n\n## Why Use It?\n\nWhen you use libraries that raise their own errors, it's not a good idea to allow these errors to bubble up through your app/library. Clients of your app/library should only have to deal with errors that belong to your app and not ones that come from libraries that your app is using. To achieve this without nested exception support, you would need to rescue the error that come from external libraries and then raise your own errors in their place. Of course, when you do this you lose the information from the original error. With nested exception support you no longer have to lose this information which is very handy.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n    gem 'nesty'\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install nesty\n\n## Usage\n\nSuper simple, create your own error class just like normal, but include a module in it:\n\n```ruby\nclass HappyError \u003c StandardError\n  include Nesty::NestedError\nend\n```\n\nAlternatively rather than inheriting from `StandardError` do this:\n\n```ruby\nHappyError = Class.new(Nesty::NestedStandardError)\n```\n\nInstances of `HappyError` will now support nesting another error inside.\n\nHere is how we can use this:\n\n```ruby\nbegin\n  raise StandardError.new\nrescue =\u003e e\n  raise HappyError.new(\"hello\", e)\nend\n```\n\nThat was the explicit way, you raise another error and pass in the error you rescued, but you can also do this:\n\n```ruby\nbegin\n  raise StandardError.new\nrescue =\u003e e\n  raise HappyError.new\nend\n```\n\nThis is the implicit way, the `HappyError` instance will still nest the `StandardError` that was rescued.\n\nYou can of course go deeper and keep rescuing and raising your own errors. As long as you raise with instances that support nesting (e.g. ones that include `Nesty::NestedError` or inherit from `Nesty::NestedStandardError`), the stacktrace will include all the nested exception messages.\n\n### What The Stacktrace Will Look Like?\n\nIt's probably a good idea to keep the stacktrace as close to a normal one as possible and in this case it actually will look very similar to a normal stacktrace. The only difference is that the error messages for all the nested errors will be included in the stacktrace (as opposed to just the message for the outer error).\n\nLet's illustrate with an example.\n\nWe have 3 errors, A, B and C all nested in each other (A is nested in B and B is nested in C). They have the following messages and backtrace arrays:\n\n```\nA - message: 'a', backtrace: ['2', '1']\nB - message: 'b', backtrace: ['4', '3', '2', '1']\nC - message: 'c', backtrace: ['6', '5', '4', '3', '2', '1']\n```\n\nIf C was not nested and we allowed it to bubble up so that it gets dumped to standard output, we would see something like the following:\n\n```\nc\n6\n5\n4\n3\n2\n1\n```\n\nBut, with out nested errors we would see the following:\n\n```\nc\n6\n5\n4: b\n3\n2: a\n1\n```\n\nSince a stacktrace for a nested error is always a subset of the stacktrace of the enclosing error, all we need to do is add the messages for each of our nested errors in the appropriate place in the stacktrace. Simple, but handy.\n\n## Contributing\n\n1. Fork it\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create new Pull Request\n","funding_links":[],"categories":["Error Handling","Ruby"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fskorks%2Fnesty","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fskorks%2Fnesty","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fskorks%2Fnesty/lists"}