File tree Expand file tree Collapse file tree 2 files changed +7
-17
lines changed
chain/vm/src/host/vm_hooks/vh_handler
framework/base/src/types/managed/basic Expand file tree Collapse file tree 2 files changed +7
-17
lines changed Original file line number Diff line number Diff line change 11use multiversx_chain_core:: types:: ReturnCode ;
22use multiversx_chain_vm_executor:: VMHooksEarlyExit ;
33
4- use crate :: {
5- host:: vm_hooks:: { VMHooksContext , vh_early_exit:: early_exit_vm_error} ,
6- types:: RawHandle ,
7- } ;
4+ use crate :: { host:: vm_hooks:: VMHooksContext , types:: RawHandle } ;
85
96use super :: VMHooksHandler ;
107
118impl < C : VMHooksContext > VMHooksHandler < C > {
129 pub fn signal_error ( & mut self , message : & [ u8 ] ) -> Result < ( ) , VMHooksEarlyExit > {
13- match String :: from_utf8 ( message. to_owned ( ) ) {
14- Ok ( message_string) => {
15- self . error_trace ( & message_string) ;
16- Err ( VMHooksEarlyExit :: new ( ReturnCode :: UserError . as_u64 ( ) )
17- . with_message ( message_string) )
18- }
19- Err ( _) => Err ( early_exit_vm_error ( "error message utf-8 error" ) ) ,
20- }
10+ let message_string = String :: from_utf8_lossy ( message) ;
11+ self . error_trace ( & message_string) ;
12+ Err ( VMHooksEarlyExit :: new ( ReturnCode :: UserError . as_u64 ( ) )
13+ . with_message ( message_string. to_string ( ) ) )
2114 }
2215
2316 pub fn signal_error_from_buffer (
Original file line number Diff line number Diff line change @@ -583,11 +583,8 @@ impl<M: ManagedTypeApi> core::fmt::Debug for ManagedBuffer<M> {
583583
584584impl < M : ManagedTypeApi > core:: fmt:: Display for ManagedBuffer < M > {
585585 fn fmt ( & self , f : & mut core:: fmt:: Formatter < ' _ > ) -> core:: fmt:: Result {
586- use crate :: contract_base:: ErrorHelper ;
587-
588- let s = alloc:: string:: String :: from_utf8 ( self . to_boxed_bytes ( ) . into_vec ( ) )
589- . unwrap_or_else ( |err| ErrorHelper :: < M > :: signal_error_with_message ( err. as_bytes ( ) ) ) ;
590-
586+ let bytes = self . to_boxed_bytes ( ) ;
587+ let s = alloc:: string:: String :: from_utf8_lossy ( bytes. as_slice ( ) ) ;
591588 s. fmt ( f)
592589 }
593590}
You can’t perform that action at this time.
0 commit comments