Add 'library', 'reason' Attribute to ssl.SSLError

This commit is contained in:
TaeGit committed 2022-08-14 04:52:31 +09:00
1 parent aec155f050
commit 93d411d50a
1 file changed
+7
+7
View File
@@ -1150,10 +1150,17 @@ mod _ssl {
// TODO: map the error codes to code names, e.g. "CERTIFICATE_VERIFY_FAILED", just requires a big hashmap/dict
let errstr = e.reason().unwrap_or("unknown error");
let msg = if let Some(lib) = e.library() {
// add `library` attribute
let attr_name = vm.ctx.as_ref().intern_str("library");
cls.set_attr(attr_name, vm.ctx.new_str(lib).into());
format!("[{}] {} ({}:{})", lib, errstr, file, line)
} else {
format!("{} ({}:{})", errstr, file, line)
};
// add `reason` attribute
let attr_name = vm.ctx.as_ref().intern_str("reason");
cls.set_attr(attr_name, vm.ctx.new_str(errstr).into());
let reason = sys::ERR_GET_REASON(e.code());
vm.new_exception(
cls,