Fix SSL error handling by youknowone · Pull Request #6351 · RustPython/RustPython
PEM error calls pass empty reason string; swap reason/message usage
In load_cert_chain, the non-password PEM error paths build the SSL error as:
super::compat::SslError::create_ssl_error_with_reason( vm, Some("SSL"), "", "PEM lib", )
(and similarly in the _ and non-io::Error branches).
Per create_ssl_error_with_reason’s contract and other call sites, reason should hold a short reason like "PEM lib", while message is the main display string. Using an empty reason here means exc.reason is not informative and is inconsistent with comments like // [SSL] PEM lib and with usages such as the NO_START_LINE path.
Recommend at least giving reason a non-empty value and, ideally, including the [SSL] … prefix in the message, e.g.:
- super::compat::SslError::create_ssl_error_with_reason( - vm, - Some("SSL"), - "", - "PEM lib", - ) + super::compat::SslError::create_ssl_error_with_reason( + vm, + Some("SSL"), + "PEM lib", + "[SSL] PEM lib", + )
Apply the same pattern to the _ arm and the else branch so that all PEM-lib errors expose a consistent and non-empty reason attribute.
🤖 Prompt for AI Agents
In crates/stdlib/src/ssl.rs around lines 1256 to 1280, the PEM error branches
call create_ssl_error_with_reason(vm, Some("SSL"), "", "PEM lib") leaving the
reason empty; change these calls so reason receives a short non-empty identifier
(e.g. "PEM lib") and message receives the full display string (e.g. "[SSL] PEM
lib" or include context), i.e. swap the empty-string reason and the current
message value so exc.reason is informative; apply the same change to the `_` arm
and the final `else` branch so all PEM parsing error paths consistently pass a
non-empty reason and an appropriate message.