check the result here
diff --git a/OpenSSL/crypto.py b/OpenSSL/crypto.py
index 9ff2e70..60b2c9b 100644
--- a/OpenSSL/crypto.py
+++ b/OpenSSL/crypto.py
@@ -1615,10 +1615,10 @@
             "type argument must be FILETYPE_PEM, FILETYPE_ASN1, or "
             "FILETYPE_TEXT")
 
+    assert result_code == 0
     return _bio_to_string(bio)
 
 
-
 def dump_privatekey(type, pkey, cipher=None, passphrase=None):
     """
     Dump a private key to a buffer