{"id":29271559,"url":"https://github.com/ktchen14/rescue-with","last_synced_at":"2025-10-08T04:19:47.435Z","repository":{"id":56891900,"uuid":"127368478","full_name":"ktchen14/rescue-with","owner":"ktchen14","description":"Adds `... rescue ExceptionType.with { ... }` to Ruby","archived":false,"fork":false,"pushed_at":"2018-04-09T07:38:08.000Z","size":5,"stargazers_count":13,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-05T00:29:54.502Z","etag":null,"topics":["ruby"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ktchen14.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}},"created_at":"2018-03-30T02:00:28.000Z","updated_at":"2018-07-28T06:15:13.000Z","dependencies_parsed_at":"2022-08-21T00:20:44.843Z","dependency_job_id":null,"html_url":"https://github.com/ktchen14/rescue-with","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ktchen14/rescue-with","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ktchen14%2Frescue-with","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ktchen14%2Frescue-with/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ktchen14%2Frescue-with/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ktchen14%2Frescue-with/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ktchen14","download_url":"https://codeload.github.com/ktchen14/rescue-with/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ktchen14%2Frescue-with/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265132474,"owners_count":23716179,"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":["ruby"],"created_at":"2025-07-05T00:00:54.090Z","updated_at":"2025-10-08T04:19:47.357Z","avatar_url":"https://github.com/ktchen14.png","language":"Ruby","readme":"# rescue-with\n\nInline rescue a specific exception type in Ruby.\n\n## Background\n\nThe modifier form of `rescue` in Ruby\n[can](https://github.com/bbatsov/ruby-style-guide#no-rescue-modifiers)\n[be](https://rubocop.readthedocs.io/en/latest/cops_style/#stylerescuemodifier)\n[dangerous](https://www.rubytapas.com/2012/11/12/episode-022-inline-rescue/)\nbecause it rescues from `StandardError` and can't be targeted toward a more\nspecific exception. To rescue from a specific exception the full `begin ...\nrescue ... end` syntax must be used which can be needlessly verbose as evident\nfrom this [proposal](https://bugs.ruby-lang.org/issues/6739) from 2013.\n\n## Installation\n\n```\ngem install rescue-with\n```\n\n## Usage\n\nTo use this gem required it with:\n\n```ruby\nrequire 'rescue-with'\n```\n\nThis gem adds the syntax:\n\n```ruby\n... rescue ExceptionType.with { ... }\n```\n\nTo rescue from `ExceptionType` and return the result `{ ... }`. If you need the\nexception itself and don't want to use `$!` then do:\n\n```ruby\n... rescue ExceptionType.with { |e| ... }\n```\n\n## Example\n\nOutput an error message to `stderr` if a file can't be read:\n\n```ruby\ndata = File.read('none') rescue Errno::ENOENT.with { $stderr.puts('No data') }\n```\n\n## Caveats\n\nBecause the modifier form of `rescue` only rescues from `StandardError` this\nsyntax only works if `StandardError` is an ancestor of `ExceptionType`. This\nshouldn't be a problem most of the time as `Exception`s that aren't a subclass\nof `StandardError` are rarely rescued.\n\nNote that `StandardError#with` only rescues a single type of exception. If you\nneed to rescue multiple types of exceptions it's much better to use the `begin\n... rescue ... end` syntax.\n\n## License\n\nThe gem is available as open source under the terms of [The\nUnlicense](http://unlicense.org/).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fktchen14%2Frescue-with","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fktchen14%2Frescue-with","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fktchen14%2Frescue-with/lists"}