{"id":13878751,"url":"https://github.com/ruby/error_highlight","last_synced_at":"2025-09-25T11:12:12.405Z","repository":{"id":38314284,"uuid":"381297545","full_name":"ruby/error_highlight","owner":"ruby","description":"The gem enhances Exception#message by adding a short explanation where the exception is raised","archived":false,"fork":false,"pushed_at":"2025-08-28T06:35:05.000Z","size":75,"stargazers_count":152,"open_issues_count":6,"forks_count":26,"subscribers_count":34,"default_branch":"master","last_synced_at":"2025-08-28T13:04:31.108Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ruby.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2021-06-29T08:44:01.000Z","updated_at":"2025-08-28T06:35:09.000Z","dependencies_parsed_at":"2024-06-07T14:44:54.438Z","dependency_job_id":"a5c0d20e-7955-4a61-a620-fbea694bc783","html_url":"https://github.com/ruby/error_highlight","commit_stats":{"total_commits":69,"total_committers":16,"mean_commits":4.3125,"dds":"0.37681159420289856","last_synced_commit":"a8e9eb7f2f4cd553b5113f05c0478bcfdaec59f4"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/ruby/error_highlight","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ruby%2Ferror_highlight","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ruby%2Ferror_highlight/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ruby%2Ferror_highlight/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ruby%2Ferror_highlight/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ruby","download_url":"https://codeload.github.com/ruby/error_highlight/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ruby%2Ferror_highlight/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":276905427,"owners_count":25725561,"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","status":"online","status_checked_at":"2025-09-25T02:00:09.612Z","response_time":80,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["ruby"],"created_at":"2024-08-06T08:01:58.759Z","updated_at":"2025-09-25T11:12:12.361Z","avatar_url":"https://github.com/ruby.png","language":"Ruby","readme":"# ErrorHighlight\n\n## Installation\n\nRuby 3.1 will ship with this gem and it will automatically be `require`d when a Ruby process starts up. No special setup is required.\n\nNote: This gem works only on MRI and requires Ruby 3.1 or later because it depends on MRI's internal APIs that are available since 3.1.\n\n## Examples\n\n```ruby\n1.time {}\n```\n\n```\n$ ruby test.rb\ntest.rb:1:in `\u003cmain\u003e': undefined method `time' for 1:Integer (NoMethodError)\n\n1.time {}\n ^^^^^\nDid you mean?  times\n```\n\n## More example\n\n```ruby\ndef extract_value(data)\n  data[:results].first[:value]\nend\n```\n\nWhen `data` is `{ :results =\u003e [] }`, the following error message is shown:\n\n```\n$ ruby test.rb\ntest.rb:2:in `extract_value': undefined method `[]' for nil:NilClass (NoMethodError)\n\n  data[:results].first[:value]\n                      ^^^^^^^^\n        from test.rb:5:in `\u003cmain\u003e'\n```\n\nWhen `data` is `nil`, it prints:\n\n```\n$ ruby test.rb\ntest.rb:2:in `extract_value': undefined method `[]' for nil:NilClass (NoMethodError)\n\n  data[:results].first[:value]\n      ^^^^^^^^^^\n        from test.rb:5:in `\u003cmain\u003e'\n```\n\n## Using the `ErrorHighlight.spot`\n\n*Note: This API is experimental, may change in future.*\n\nYou can use the `ErrorHighlight.spot` method to get the snippet data.\nNote that the argument must be a RubyVM::AbstractSyntaxTree::Node object that is created with `keep_script_lines: true` option (which is available since Ruby 3.1).\n\n```ruby\nclass Dummy\n  def test(_dummy_arg)\n    node = RubyVM::AbstractSyntaxTree.of(caller_locations.first, keep_script_lines: true)\n    ErrorHighlight.spot(node)\n  end\nend\n\npp Dummy.new.test(42) # \u003c- Line 8\n#           ^^^^^       \u003c- Column 12--17\n\n#=\u003e {:first_lineno=\u003e8,\n#    :first_column=\u003e12,\n#    :last_lineno=\u003e8,\n#    :last_column=\u003e17,\n#    :snippet=\u003e\"pp Dummy.new.test(42) # \u003c- Line 8\\n\"}\n```\n\n## Custom Formatter\n\nIf you want to customize the message format for code snippet, use `ErrorHighlight.formatter=` to set your custom object that responds to `message_for` method.\n\n```ruby\nformatter = Object.new\ndef formatter.message_for(spot)\n  marker = \" \" * spot[:first_column] + \"^\" + \"~\" * (spot[:last_column] - spot[:first_column] - 1)\n\n  \"\\n\\n#{ spot[:snippet] }#{ marker }\"\nend\n\nErrorHighlight.formatter = formatter\n\n1.time {}\n\n#=\u003e\n#\n# test.rb:10:in `\u003cmain\u003e': undefined method `time' for 1:Integer (NoMethodError)\n#\n# 1.time {}\n#  ^~~~~\n# Did you mean?  times\n```\n\n## Disabling `error_highlight`\n\nOccasionally, you may want to disable the `error_highlight` gem for e.g. debugging issues in the error object itself. You\ncan disable it entirely by specifying `--disable-error_highlight` option to the `ruby` command:\n\n```bash\n$ ruby --disable-error_highlight -e '1.time {}'\n-e:1:in `\u003cmain\u003e': undefined method `time' for 1:Integer (NoMethodError)\nDid you mean?  times\n```\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/ruby/error_highlight.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n","funding_links":[],"categories":["Ruby"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fruby%2Ferror_highlight","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fruby%2Ferror_highlight","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fruby%2Ferror_highlight/lists"}