diff options
author | Kazuki Yamaguchi <k@rhe.jp> | 2018-09-20 01:48:44 +0900 |
---|---|---|
committer | Kazuki Yamaguchi <k@rhe.jp> | 2018-09-20 01:48:44 +0900 |
commit | 2048eb3e0be0727419b2ca033e74c56041d1a56a (patch) | |
tree | ac8420f7684bf2de025bdf40db4652f612ad473c /ext/openssl/ossl.c | |
parent | cb710f1b048e9d9dbd37de2a1f6a7c236f20dd00 (diff) | |
download | ruby-openssl-ky/ossl-raise-extra-data.tar.gz |
ossl.c: let ossl_raise() generate more informative error messageky/ossl-raise-extra-data
An OpenSSL error queue item sometimes contains additional information
which may be helpful for debugging.
Note, in previous versions, the debug print of OpenSSL.debug already
contained such information.
Diffstat (limited to 'ext/openssl/ossl.c')
-rw-r--r-- | ext/openssl/ossl.c | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/ext/openssl/ossl.c b/ext/openssl/ossl.c index fb34da68..ec1687d6 100644 --- a/ext/openssl/ossl.c +++ b/ext/openssl/ossl.c @@ -267,21 +267,32 @@ ossl_make_error(VALUE exc, const char *fmt, va_list args) { VALUE str = Qnil; unsigned long e; + const char *file, *data; + int line, flags; if (fmt) { str = rb_vsprintf(fmt, args); } - e = ERR_peek_last_error(); + e = ERR_peek_last_error_line_data(&file, &line, &data, &flags); if (e) { - const char *msg = ERR_reason_error_string(e); - - if (NIL_P(str)) { - if (msg) str = rb_str_new_cstr(msg); - } + const char *reason = ERR_reason_error_string(e); + if (!reason) + reason = "(null)"; + if (NIL_P(str)) + str = rb_str_new_cstr(reason); else { - if (RSTRING_LEN(str)) rb_str_cat2(str, ": "); - rb_str_cat2(str, msg ? msg : "(null)"); + rb_str_cat_cstr(str, ": "); + rb_str_cat_cstr(str, reason); } + + if (flags & ERR_TXT_STRING) { + if (!data) + data = "(null)"; + rb_str_cat_cstr(str, " ("); + rb_str_cat_cstr(str, data); + rb_str_cat_cstr(str, ")"); + } + ossl_clear_error(); } |