Issue #14278 has been updated by KINGSABRI (KING SABRI).


Hanmac (Hans Mackowiak) wrote:
> the Error Message is common for all other stuff, check for example File.read(nil) has same error:
> 
> ~~~
> TypeError: no implicit conversion of nil into String
> ~~~
> 
> 
> implicit conversion means that while an object might has a to_s method like nil, it doesn't has a to_str method
> (difference between explicit and implicit conversion)
> 
> the moment when digest does try to convert nil into string, it doesn't know the variable name for this
> 
> ---
> 
> 
> similar error:
> 
> ~~~
> 3 * "w"
> TypeError: String can't be coerced into Integer
> ~~~
> this one means that it failed the coerce between Numeric types

Thanks for your reply, and yeah that's the point. Errors must be more specific to reduce debugging and troubleshooting time. 

so instead of going to look into the object code to understand the class/module/method code itself, it should be some clear error that helps me to fix my code. 







----------------------------------------
Bug #14278: Ambiguous Exception for OpenSSL::HMAC.digest
https://bugs.ruby-lang.org/issues/14278#change-69203

* Author: KINGSABRI (KING SABRI)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: ruby 2.4.2p198 (2017-09-14 revision 59899) [x86_64-linux-gnu]
* Backport: 2.3: UNKNOWN, 2.4: UNKNOWN, 2.5: UNKNOWN
----------------------------------------
The `OpenSSL::HMAC.digest` shows unclear and ambiguous exception when key is nil.


~~~ ruby
require 'openssl'

key = nil
OpenSSL::HMAC.digest(OpenSSL::Digest.new('sha256'), key, 'RubyRuby')
TypeError: no implicit conversion of nil into String
`digest'
~~~

**Expected Behavior**
So clear and understandable issue, such: 

~~~ text
key argument cannot be nil for OpenSSL::HMAC.digest
~~~








-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>