Issue #18915 has been updated by zverok (Victor Shepelev).
The new exception class should inherit from ScriptError, not StandardError. Failing to define a method that a subclass is required to provide is a problem in the program itself, the same kind of problem as SyntaxError or LoadError, not a runtime error.
@matz, we just discussed this future change with colleagues (got bit by `NotImplementedError` in our codebase, and I remembered the ongoing core discussion), and I think they made a good counter-argument: **The "this object's method is not implemented" is an error of the same severity class as "this object doesn't have such method at all" (aka `NoMethodError`), and the latter is a descendant of a `StandardError`.** The difference from `SyntaxError`/`LoadError` is that "this method is not implemented" usually happens in runtime, not while the codebase is loaded, and so it not being caught by standard `rescue` might be undesirable. Imagine some code like: ```ruby payloads.each do |payload| driver = Driver.create_for(payload[:type]) # fetches different Driver subclasses driver.process(payload) rescue => ex log.error("payload #{payload} is unprocessable: #{ex.message}") end ``` If we have like 10 different drivers, and one of them didn't implement the necessary method, this will bite the developer somewhere in the middle of the code handling something, not in a "code can't be loaded at all" way. WDYT? ---------------------------------------- Feature #18915: New error class: NotImplementedYetError or scope change for NotImplementedError https://bugs.ruby-lang.org/issues/18915#change-118523 * Author: Quintasan (Michał Zając) * Status: Open ---------------------------------------- # Abstract Introduce `NotImplementedYetError` exception that should be used in case when the codepath has not been implemented by the developer for some reason (maybe they're designing an abstract class or are designing some sort of interface to reuse later on) OR extend the meaning of `NotImplementedError` to cover those usecases so we don't have to introduce another exception # Background `NotImplementedError` is supposed to be raised `if the underlying operating system or Ruby runtime does not support them` (https://ruby-doc.org/core-3.1.2/NotImplementedError.html) However it appears that many people are misusing this exception by raising this in a superclass from which they later inherit from. I do realize that Ruby promotes duck-typing (the default RuboCop style guide has a cop for this – https://github.com/rubocop/ruby-style-guide#duck-typing). However I have seen this being discussed numerous times: * https://github.com/rubocop/ruby-style-guide/issues/458 * http://chrisstump.online/2016/03/23/stop-abusing-notimplementederror/ * https://oleg0potapov.medium.com/ruby-notimplementederror-dont-use-it-dff1fd7... * https://gitlab.com/gitlab-org/gitlab/-/issues/354314 (which I'm the author of) * https://github.com/rmosolgo/graphql-ruby/issues/2067 (here the author actually confused it with Python's `NotImplementedError`) * https://stackoverflow.com/questions/13668068/how-to-signal-not-implemented-y... # Proposal Create `NotImplementedYetError` exception OR Allow raising `NotImplementedError` in cases other than OS or Ruby runtime incompatibilities # Evaluation ### Add `NotImplementedYetError` I think a new exception is a better idea than changing the usage of an existing one just because "everyone is using it". That said it would require people to refactor their code which might prevent wider adoption of the new exception. ### Change scope of `NotImplementedError` This would require the least amount of changes possible (only a documentation change) and I believe there would be no compatibility problems whatsoever. ---Files-------------------------------- not-implemented-error-docs.patch (1.57 KB) -- https://bugs.ruby-lang.org/