Skip to content

Commit

Permalink
cleanup error code
Browse files Browse the repository at this point in the history
  • Loading branch information
Robin committed Jun 12, 2022
1 parent b86592c commit b34be4b
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/types/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use crate::{
Python, ToPyObject,
};
use std::borrow::Cow;
use std::ffi::CStr;
use std::os::raw::c_char;
use std::str;

Expand Down Expand Up @@ -236,13 +237,13 @@ impl PyString {
(0..len).map(move |i| {
let c = ffi::PyUnicode_ReadChar(self.as_ptr(), i);
char::from_u32(c).ok_or_else(|| {
exceptions::PyUnicodeDecodeError::new_err((
"utf-32",
PyBytes::new(self.py(), &c.to_ne_bytes()).to_object(self.py()),
i,
i + 1,
format!("invalid codepoint"),
))
exceptions::PyUnicodeDecodeError::new(
self.py(),
CStr::from_bytes_with_nul(b"utf-8\0").unwrap(),
&c.to_ne_bytes(),
i as usize..(i + 1) as usize,
CStr::from_bytes_with_nul(b"invalid codepoint\0").unwrap(),
)
})
})
}
Expand Down

0 comments on commit b34be4b

Please sign in to comment.