123456789_123456789_123456789_123456789_123456789_

Exception: OpenSSL::OpenSSLError

Overview

Generic error class for ::OpenSSL. All error classes in this library inherit from this class.

This class indicates that an error was reported by the underlying OpenSSL library.

Instance Attribute Summary

  • #errors readonly

    OpenSSL error queue entries captured at the time the exception was raised.

Instance Method Summary

Instance Attribute Details

#errors (readonly)

OpenSSL error queue entries captured at the time the exception was raised. The same information is printed to stderr if OpenSSL.debug is set to true.

This is an array of zero or more strings, ordered from the oldest to the newest. The format of the strings is not stable and may vary across versions of OpenSSL or versions of this Ruby extension.

See also the man page ERR_get_error(3).

[ GitHub ]

Instance Method Details

#detailed_message(**) ⇒ String

Returns the exception message decorated with the captured OpenSSL error queue entries.

[ GitHub ]

  
# File 'ext/openssl/ossl.c', line 359

static VALUE
osslerror_detailed_message(int argc, VALUE *argv, VALUE self)
{
    VALUE str;
#ifdef HAVE_RB_CALL_SUPER_KW
    // Ruby >= 3.2
    if (RTEST(rb_funcall(rb_eException, rb_intern("method_defined?"), 1,
                         ID2SYM(rb_intern("detailed_message")))))
        str = rb_call_super_kw(argc, argv, RB_PASS_CALLED_KEYWORDS);
    else
#endif
        str = rb_funcall(self, rb_intern("message"), 0);
    VALUE errors = rb_attr_get(self, id_i_errors);

    // OpenSSLError was not created by ossl_make_error()
    if (!RB_TYPE_P(errors, T_ARRAY))
        return str;

    str = rb_str_resurrect(str);
    rb_str_catf(str, "\nOpenSSL error queue reported %ld errors:",
                RARRAY_LEN(errors));
    for (long i = 0; i < RARRAY_LEN(errors); i++) {
        VALUE err = RARRAY_AREF(errors, i);
        rb_str_catf(str, "\n%"PRIsVALUE, err);
    }
    return str;
}