MCPcopy Index your code
hub / github.com/RustPython/RustPython / error_decoding

Method error_decoding

crates/vm/src/codecs.rs:761–798  ·  view source on GitHub ↗
(&self, byte_range: Range<usize>, reason: Option<&str>)

Source from the content-addressed store, hash-verified

759 }
760
761 fn error_decoding(&self, byte_range: Range<usize>, reason: Option<&str>) -> Self::Error {
762 let vm = self.vm;
763
764 match self.exception.get() {
765 Some(exc) => {
766 match update_unicode_error_attrs(
767 exc.as_object(),
768 byte_range.start,
769 byte_range.end,
770 reason,
771 vm,
772 ) {
773 Ok(()) => exc.clone(),
774 Err(e) => e,
775 }
776 }
777 None => self
778 .exception
779 .get_or_init(|| {
780 let reason = reason.expect(
781 "should only ever pass reason: None if an exception is already set",
782 );
783 let data = if let Some(bytes) = self.orig_bytes {
784 bytes.to_owned()
785 } else {
786 vm.ctx.new_bytes(self.data.to_vec())
787 };
788 vm.new_unicode_decode_error_real(
789 vm.ctx.new_str(self.encoding),
790 data,
791 byte_range.start,
792 byte_range.end,
793 vm.ctx.new_str(reason),
794 )
795 })
796 .clone(),
797 }
798 }
799}
800
801#[derive(strum_macros::EnumString)]

Callers 2

handle_decode_errorMethod · 0.80
handle_decode_errorMethod · 0.80

Calls 10

to_vecMethod · 0.80
getMethod · 0.45
as_objectMethod · 0.45
cloneMethod · 0.45
get_or_initMethod · 0.45
to_ownedMethod · 0.45
new_bytesMethod · 0.45
new_strMethod · 0.45

Tested by

no test coverage detected