@@ -978,19 +978,30 @@ fn ssl_error(vm: &VirtualMachine) -> PyTypeRef {
978
978
vm. class ( "_ssl" , "SSLError" )
979
979
}
980
980
981
+ #[ track_caller]
981
982
fn convert_openssl_error ( vm : & VirtualMachine , err : ErrorStack ) -> PyBaseExceptionRef {
982
983
let cls = ssl_error ( vm) ;
983
984
match err. errors ( ) . last ( ) {
984
985
Some ( e) => {
986
+ let caller = std:: panic:: Location :: caller ( ) ;
987
+ let ( file, line) = ( caller. file ( ) , caller. line ( ) ) ;
988
+ let file = file
989
+ . rsplit_once ( & [ '/' , '\\' ] [ ..] )
990
+ . map_or ( file, |( _, basename) | basename) ;
985
991
// TODO: map the error codes to code names, e.g. "CERTIFICATE_VERIFY_FAILED", just requires a big hashmap/dict
986
992
let errstr = e. reason ( ) . unwrap_or ( "unknown error" ) ;
987
- let msg = format ! ( "{} (_ssl.c:{})" , errstr, e. line( ) ) ;
993
+ let msg = if let Some ( lib) = e. library ( ) {
994
+ format ! ( "[{}] {} ({}:{})" , lib, errstr, file, line)
995
+ } else {
996
+ format ! ( "{} ({}:{})" , errstr, file, line)
997
+ } ;
988
998
let reason = sys:: ERR_GET_REASON ( e. code ( ) ) ;
989
999
vm. new_exception ( cls, vec ! [ vm. ctx. new_int( reason) , vm. ctx. new_utf8_str( msg) ] )
990
1000
}
991
1001
None => vm. new_exception_empty ( cls) ,
992
1002
}
993
1003
}
1004
+ #[ track_caller]
994
1005
fn convert_ssl_error (
995
1006
vm : & VirtualMachine ,
996
1007
e : impl std:: borrow:: Borrow < ssl:: Error > ,
0 commit comments