Repository: nervosnetwork/ckb-std (language: rust)

Issue:
exec_cell should return Result<!, SysError>
If it succeeds, it won't return.

(But `!` is usable in stable yet, if we don't want to use the nightly feature, we can use `Infallible` instead.)


Discussion / hints:

Fix patch:
diff --git a/src/high_level.rs b/src/high_level.rs
index 64eef1c..d0f11a5 100644
--- a/src/high_level.rs
+++ b/src/high_level.rs
@@ -4,6 +4,7 @@ use crate::error::SysError;
 use crate::syscalls;
 use alloc::{vec, vec::Vec};
 use ckb_types::{core::ScriptHashType, packed::*, prelude::*};
+use core::convert::Infallible;
 use core::ffi::CStr;
 
 /// Default buffer size
@@ -604,12 +605,18 @@ pub fn exec_cell(
     offset: u32,
     length: u32,
     argv: &[&CStr],
-) -> Result<u64, SysError> {
+) -> Result<Infallible, SysError> {
     #[cfg(not(feature = "simulator"))]
     {
         let index = look_for_dep_with_hash2(code_hash, hash_type)?;
         let bounds: usize = (offset as usize) << 32 | (length as usize);
-        Ok(syscalls::exec(index, Source::CellDep, 0, bounds, argv))
+        let ret = syscalls::exec(index, Source::CellDep, 0, bounds, argv);
+        let err = match ret {
+            1 => SysError::IndexOutOfBound,
+            2 => SysError::ItemMissing,
+            r => SysError::Unknown(r)
+        };
+        Err(err)
     }
     #[cfg(feature = "simulator")]
     syscalls::exec_cell(code_hash, hash_type, offset, length, argv)
diff --git a/src/syscalls/simulator.rs b/src/syscalls/simulator.rs
index 4ecebf7..ceaa706 100644
--- a/src/syscalls/simulator.rs
+++ b/src/syscalls/simulator.rs
@@ -2,6 +2,7 @@ use crate::{ckb_constants::*, error::SysError};
 use ckb_types::core::ScriptHashType;
 use ckb_x64_simulator as sim;
 use core::ffi::{c_void, CStr};
+use core::convert::Infallible;
 
 pub fn exit(code: i8) -> ! {
     sim::ckb_exit(code);
@@ -243,18 +244,19 @@ pub fn exec_cell(
     offset: u32,
     length: u32,
     argv: &[&CStr],
-) -> Result<u64, SysError> {
+) -> Result<Infallible, SysError> {
     let argc = argv.len();
     let mut argv_ptr = alloc::vec![core::ptr::null(); argc + 1];
     for (idx, cstr) in argv.into_iter().enumerate() {
         argv_ptr[idx] = cstr.to_bytes_with_nul().as_ptr();
     }
-    Ok(sim::ckb_exec_cell(
+    let ret = sim::ckb_exec_cell(
         code_hash.as_ptr(),
         hash_type as u8,
         offset,
         length,
         argc as i32,
         argv_ptr.as_ptr(),
-    ) as i64 as u64)
+    );
+    Err(SysError::Unknown(ret as u64))
 }


Test patch: