Repository: wasmerio/wasmer (language: rust)

Issue:
Can Wasi ExitCode be negative?
### Summary

A clear and concise summary of your question.

I see that https://docs.rs/wasmer-wasix-types/0.27.0/wasmer_wasix_types/wasi/enum.ExitCode.html has an `i32` and as such when you ask for the raw exit code it gives an `i32`.

But after searching around a bit, I don't see a situation in which it would be negative. I see that `Errno` is `repr(u16)`. Can this actually be negative anywhere?

I could be missing it somewhere since a from impl exists:
```rust

impl From<ExitCode> for i32 {
    fn from(val: ExitCode) -> Self {
        match val {
            ExitCode::Errno(err) => err.to_native(),
            ExitCode::Other(code) => code,
        }
    }
}
```

### Additional details

N/A



Discussion / hints:
Thanks for the report, seems like a bug on our side. 

Fix patch:
diff --git a/lib/journal/src/concrete/archived_from.rs b/lib/journal/src/concrete/archived_from.rs
index 724526986f1..49005c8f3a4 100644
--- a/lib/journal/src/concrete/archived_from.rs
+++ b/lib/journal/src/concrete/archived_from.rs
@@ -140,20 +140,15 @@ impl From<JournalIpCidrV1> for virtual_net::IpCidr {
 
 impl From<wasi::ExitCode> for JournalExitCodeV1 {
     fn from(val: wasi::ExitCode) -> Self {
-        match val {
-            wasi::ExitCode::Errno(errno) => JournalExitCodeV1::Errno(errno as u16),
-            wasi::ExitCode::Other(id) => JournalExitCodeV1::Other(id),
-        }
+        JournalExitCodeV1::Other(val.raw())
     }
 }
 
 impl From<JournalExitCodeV1> for wasi::ExitCode {
     fn from(val: JournalExitCodeV1) -> Self {
         match val {
-            JournalExitCodeV1::Errno(errno) => {
-                wasi::ExitCode::Errno(errno.try_into().unwrap_or(wasi::Errno::Unknown))
-            }
-            JournalExitCodeV1::Other(id) => wasi::ExitCode::Other(id),
+            JournalExitCodeV1::Errno(errno) => wasi::ExitCode::from(errno),
+            JournalExitCodeV1::Other(id) => wasi::ExitCode::from(id),
         }
     }
 }
@@ -161,12 +156,8 @@ impl From<JournalExitCodeV1> for wasi::ExitCode {
 impl From<&'_ ArchivedJournalExitCodeV1> for wasi::ExitCode {
     fn from(val: &'_ ArchivedJournalExitCodeV1) -> Self {
         match val {
-            ArchivedJournalExitCodeV1::Errno(errno) => wasi::ExitCode::Errno(
-                (errno.to_native())
-                    .try_into()
-                    .unwrap_or(wasi::Errno::Unknown),
-            ),
-            ArchivedJournalExitCodeV1::Other(id) => wasi::ExitCode::Other(id.to_native()),
+            ArchivedJournalExitCodeV1::Errno(errno) => wasi::ExitCode::from(errno.to_native()),
+            ArchivedJournalExitCodeV1::Other(id) => wasi::ExitCode::from(id.to_native()),
         }
     }
 }
diff --git a/lib/wasi-types/src/wasi/wasix_manual.rs b/lib/wasi-types/src/wasi/wasix_manual.rs
index b8ee2e53d8b..08ddfeda042 100644
--- a/lib/wasi-types/src/wasi/wasix_manual.rs
+++ b/lib/wasi-types/src/wasi/wasix_manual.rs
@@ -250,16 +250,11 @@ unsafe impl<M: MemorySize> ValueType for ThreadStart<M> {
 
 #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
 #[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))]
-pub enum ExitCode {
-    Errno(Errno),
-    Other(i32),
-}
+pub struct ExitCode(u16);
+
 impl ExitCode {
     pub fn raw(&self) -> i32 {
-        match self {
-            ExitCode::Errno(err) => err.to_native(),
-            ExitCode::Other(code) => *code,
-        }
+        self.0 as i32
     }
 
     pub fn is_success(&self) -> bool {
@@ -268,10 +263,7 @@ impl ExitCode {
 }
 impl core::fmt::Debug for ExitCode {
     fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
-        match self {
-            ExitCode::Errno(a) => write!(f, "ExitCode::{}", a),
-            ExitCode::Other(a) => write!(f, "ExitCode::{}", a),
-        }
+        write!(f, "ExitCode::{}", self.0)
     }
 }
 impl core::fmt::Display for ExitCode {
@@ -298,35 +290,31 @@ unsafe impl wasmer::FromToNativeWasmType for ExitCode {
 
 impl From<Errno> for ExitCode {
     fn from(val: Errno) -> Self {
-        Self::Errno(val)
+        Self((val.to_native() % 256) as u16)
     }
 }
 
 impl From<i32> for ExitCode {
     fn from(val: i32) -> Self {
-        let err = Errno::from_native(val);
-        match err {
-            Errno::Unknown => Self::Other(val),
-            err => Self::Errno(err),
-        }
+        Self((val % 256) as u16)
+    }
+}
+
+impl From<u16> for ExitCode {
+    fn from(value: u16) -> Self {
+        Self(value)
     }
 }
 
 impl From<ExitCode> for Errno {
     fn from(code: ExitCode) -> Self {
-        match code {
-            ExitCode::Errno(err) => err,
-            ExitCode::Other(code) => Errno::from_native(code),
-        }
+        Errno::from_native(code.0 as i32)
     }
 }
 
 impl From<ExitCode> for i32 {
     fn from(val: ExitCode) -> Self {
-        match val {
-            ExitCode::Errno(err) => err.to_native(),
-            ExitCode::Other(code) => code,
-        }
+        val.0 as i32
     }
 }
 
diff --git a/lib/wasix/src/syscalls/mod.rs b/lib/wasix/src/syscalls/mod.rs
index 6289c9b7486..00bb95a55fd 100644
--- a/lib/wasix/src/syscalls/mod.rs
+++ b/lib/wasix/src/syscalls/mod.rs
@@ -413,7 +413,7 @@ where
                         Poll::Pending
                     }
                 }
-                Ok(Err(err)) => Poll::Ready(Err(WasiError::Exit(ExitCode::Errno(err)))),
+                Ok(Err(err)) => Poll::Ready(Err(WasiError::Exit(ExitCode::from(err)))),
                 Err(err) => Poll::Ready(Err(err)),
             };
         }
@@ -1122,7 +1122,7 @@ pub(crate) fn deep_sleep<M: MemorySize>(
     // If there is an error then exit the process, otherwise we are done
     match res {
         Errno::Success => Ok(()),
-        err => Err(WasiError::Exit(ExitCode::Errno(err))),
+        err => Err(WasiError::Exit(ExitCode::from(err))),
     }
 }
 
diff --git a/lib/wasix/src/syscalls/wasi/clock_time_set.rs b/lib/wasix/src/syscalls/wasi/clock_time_set.rs
index 27a618aae53..8731adc77ab 100644
--- a/lib/wasix/src/syscalls/wasi/clock_time_set.rs
+++ b/lib/wasix/src/syscalls/wasi/clock_time_set.rs
@@ -22,7 +22,7 @@ pub fn clock_time_set<M: MemorySize>(
         if env.enable_journal {
             JournalEffector::save_clock_time_set(&mut ctx, clock_id, time).map_err(|err| {
                 tracing::error!("failed to save clock time set event - {}", err);
-                WasiError::Exit(ExitCode::Errno(Errno::Fault))
+                WasiError::Exit(ExitCode::from(Errno::Fault))
             })?;
         }
     }
diff --git a/lib/wasix/src/syscalls/wasi/fd_advise.rs b/lib/wasix/src/syscalls/wasi/fd_advise.rs
index d3e79ce7bb4..84e916f0d5c 100644
--- a/lib/wasix/src/syscalls/wasi/fd_advise.rs
+++ b/lib/wasix/src/syscalls/wasi/fd_advise.rs
@@ -27,7 +27,7 @@ pub fn fd_advise(
     if env.enable_journal {
         JournalEffector::save_fd_advise(&mut ctx, fd, offset, len, advice).map_err(|err| {
             tracing::error!("failed to save file descriptor advise event - {}", err);
-            WasiError::Exit(ExitCode::Errno(Errno::Fault))
+            WasiError::Exit(ExitCode::from(Errno::Fault))
         })?;
     }
 
diff --git a/lib/wasix/src/syscalls/wasi/fd_allocate.rs b/lib/wasix/src/syscalls/wasi/fd_allocate.rs
index ab290193cab..b9d00be2616 100644
--- a/lib/wasix/src/syscalls/wasi/fd_allocate.rs
+++ b/lib/wasix/src/syscalls/wasi/fd_allocate.rs
@@ -24,7 +24,7 @@ pub fn fd_allocate(
     if env.enable_journal {
         JournalEffector::save_fd_allocate(&mut ctx, fd, offset, len).map_err(|err| {
             tracing::error!("failed to save file descriptor allocate event - {}", err);
-            WasiError::Exit(ExitCode::Errno(Errno::Fault))
+            WasiError::Exit(ExitCode::from(Errno::Fault))
         })?;
     }
 
diff --git a/lib/wasix/src/syscalls/wasi/fd_close.rs b/lib/wasix/src/syscalls/wasi/fd_close.rs
index 6100cc2328a..f8fbbcf4b2a 100644
--- a/lib/wasix/src/syscalls/wasi/fd_close.rs
+++ b/lib/wasix/src/syscalls/wasi/fd_close.rs
@@ -36,7 +36,7 @@ pub fn fd_close(mut ctx: FunctionEnvMut<'_, WasiEnv>, fd: WasiFd) -> Result<Errn
     if env.enable_journal {
         JournalEffector::save_fd_close(&mut ctx, fd).map_err(|err| {
             tracing::error!("failed to save close descriptor event - {}", err);
-            WasiError::Exit(ExitCode::Errno(Errno::Fault))
+            WasiError::Exit(ExitCode::from(Errno::Fault))
         })?;
     }
 
diff --git a/lib/wasix/src/syscalls/wasi/fd_dup.rs b/lib/wasix/src/syscalls/wasi/fd_dup.rs
index b0d43d6d7dd..f78d1561455 100644
--- a/lib/wasix/src/syscalls/wasi/fd_dup.rs
+++ b/lib/wasix/src/syscalls/wasi/fd_dup.rs
@@ -22,7 +22,7 @@ pub fn fd_dup<M: MemorySize>(
     if env.enable_journal {
         JournalEffector::save_fd_duplicate(&mut ctx, fd, copied_fd).map_err(|err| {
             tracing::error!("failed to save file descriptor duplicate event - {}", err);
-            WasiError::Exit(ExitCode::Errno(Errno::Fault))
+            WasiError::Exit(ExitCode::from(Errno::Fault))
         })?;
     }
 
diff --git a/lib/wasix/src/syscalls/wasi/fd_event.rs b/lib/wasix/src/syscalls/wasi/fd_event.rs
index 53640876c3a..1eb85b4ea20 100644
--- a/lib/wasix/src/syscalls/wasi/fd_event.rs
+++ b/lib/wasix/src/syscalls/wasi/fd_event.rs
@@ -21,7 +21,7 @@ pub fn fd_event<M: MemorySize>(
     if env.enable_journal {
         JournalEffector::save_fd_event(&mut ctx, initial_val, flags, fd).map_err(|err| {
             tracing::error!("failed to save fd_event event - {}", err);
-            WasiError::Exit(ExitCode::Errno(Errno::Fault))
+            WasiError::Exit(ExitCode::from(Errno::Fault))
         })?;
     }
 
diff --git a/lib/wasix/src/syscalls/wasi/fd_fdstat_set_flags.rs b/lib/wasix/src/syscalls/wasi/fd_fdstat_set_flags.rs
index 2c7e15d3169..c1d1432bcbe 100644
--- a/lib/wasix/src/syscalls/wasi/fd_fdstat_set_flags.rs
+++ b/lib/wasix/src/syscalls/wasi/fd_fdstat_set_flags.rs
@@ -22,7 +22,7 @@ pub fn fd_fdstat_set_flags(
         if env.enable_journal {
             JournalEffector::save_fd_set_flags(&mut ctx, fd, flags).map_err(|err| {
                 tracing::error!("failed to save file set flags event - {}", err);
-                WasiError::Exit(ExitCode::Errno(Errno::Fault))
+                WasiError::Exit(ExitCode::from(Errno::Fault))
             })?;
         }
     }
diff --git a/lib/wasix/src/syscalls/wasi/fd_fdstat_set_rights.rs b/lib/wasix/src/syscalls/wasi/fd_fdstat_set_rights.rs
index c4d241da0e4..5158a0c7c71 100644
--- a/lib/wasix/src/syscalls/wasi/fd_fdstat_set_rights.rs
+++ b/lib/wasix/src/syscalls/wasi/fd_fdstat_set_rights.rs
@@ -30,7 +30,7 @@ pub fn fd_fdstat_set_rights(
         JournalEffector::save_fd_set_rights(&mut ctx, fd, fs_rights_base, fs_rights_inheriting)
             .map_err(|err| {
                 tracing::error!("failed to save file set rights event - {}", err);
-                WasiError::Exit(ExitCode::Errno(Errno::Fault))
+                WasiError::Exit(ExitCode::from(Errno::Fault))
             })?;
     }
 
diff --git a/lib/wasix/src/syscalls/wasi/fd_filestat_set_size.rs b/lib/wasix/src/syscalls/wasi/fd_filestat_set_size.rs
index a3b400ac81c..b9cec196f99 100644
--- a/lib/wasix/src/syscalls/wasi/fd_filestat_set_size.rs
+++ b/lib/wasix/src/syscalls/wasi/fd_filestat_set_size.rs
@@ -21,7 +21,7 @@ pub fn fd_filestat_set_size(
     if env.enable_journal {
         JournalEffector::save_fd_set_size(&mut ctx, fd, st_size).map_err(|err| {
             tracing::error!("failed to save file set size event - {}", err);
-            WasiError::Exit(ExitCode::Errno(Errno::Fault))
+            WasiError::Exit(ExitCode::from(Errno::Fault))
         })?;
     }
 
diff --git a/lib/wasix/src/syscalls/wasi/fd_filestat_set_times.rs b/lib/wasix/src/syscalls/wasi/fd_filestat_set_times.rs
index 56447883832..9711d1715fc 100644
--- a/lib/wasix/src/syscalls/wasi/fd_filestat_set_times.rs
+++ b/lib/wasix/src/syscalls/wasi/fd_filestat_set_times.rs
@@ -30,7 +30,7 @@ pub fn fd_filestat_set_times(
         JournalEffector::save_fd_set_times(&mut ctx, fd, st_atim, st_mtim, fst_flags).map_err(
             |err| {
                 tracing::error!("failed to save file set times event - {}", err);
-                WasiError::Exit(ExitCode::Errno(Errno::Fault))
+                WasiError::Exit(ExitCode::from(Errno::Fault))
             },
         )?;
     }
diff --git a/lib/wasix/src/syscalls/wasi/fd_renumber.rs b/lib/wasix/src/syscalls/wasi/fd_renumber.rs
index 39e98414566..08fdf6a55af 100644
--- a/lib/wasix/src/syscalls/wasi/fd_renumber.rs
+++ b/lib/wasix/src/syscalls/wasi/fd_renumber.rs
@@ -22,7 +22,7 @@ pub fn fd_renumber(
         if env.enable_journal {
             JournalEffector::save_fd_renumber(&mut ctx, from, to).map_err(|err| {
                 tracing::error!("failed to save file descriptor renumber event - {}", err);
-                WasiError::Exit(ExitCode::Errno(Errno::Fault))
+                WasiError::Exit(ExitCode::from(Errno::Fault))
             })?;
         }
     }
diff --git a/lib/wasix/src/syscalls/wasi/fd_seek.rs b/lib/wasix/src/syscalls/wasi/fd_seek.rs
index 527ed185dcd..3719c8455ba 100644
--- a/lib/wasix/src/syscalls/wasi/fd_seek.rs
+++ b/lib/wasix/src/syscalls/wasi/fd_seek.rs
@@ -30,7 +30,7 @@ pub fn fd_seek<M: MemorySize>(
     if env.enable_journal {
         JournalEffector::save_fd_seek(&mut ctx, fd, offset, whence).map_err(|err| {
             tracing::error!("failed to save file descriptor seek event - {}", err);
-            WasiError::Exit(ExitCode::Errno(Errno::Fault))
+            WasiError::Exit(ExitCode::from(Errno::Fault))
         })?;
     }
 
diff --git a/lib/wasix/src/syscalls/wasi/fd_write.rs b/lib/wasix/src/syscalls/wasi/fd_write.rs
index b5f0d648a82..15a654f4dd3 100644
--- a/lib/wasix/src/syscalls/wasi/fd_write.rs
+++ b/lib/wasix/src/syscalls/wasi/fd_write.rs
@@ -404,7 +404,7 @@ pub(crate) fn fd_write_internal<M: MemorySize>(
                 JournalEffector::save_fd_write(ctx, fd, offset, bytes_written, iovs, iovs_len)
                     .map_err(|err| {
                         tracing::error!("failed to save terminal data - {}", err);
-                        WasiError::Exit(ExitCode::Errno(Errno::Fault))
+                        WasiError::Exit(ExitCode::from(Errno::Fault))
                     })?;
             }
         }
diff --git a/lib/wasix/src/syscalls/wasi/path_create_directory.rs b/lib/wasix/src/syscalls/wasi/path_create_directory.rs
index fe07a65b40a..60343269fc2 100644
--- a/lib/wasix/src/syscalls/wasi/path_create_directory.rs
+++ b/lib/wasix/src/syscalls/wasi/path_create_directory.rs
@@ -44,7 +44,7 @@ pub fn path_create_directory<M: MemorySize>(
     if env.enable_journal {
         JournalEffector::save_path_create_directory(&mut ctx, fd, path_string).map_err(|err| {
             tracing::error!("failed to save create directory event - {}", err);
-            WasiError::Exit(ExitCode::Errno(Errno::Fault))
+            WasiError::Exit(ExitCode::from(Errno::Fault))
         })?;
     }
 
diff --git a/lib/wasix/src/syscalls/wasi/path_filestat_set_times.rs b/lib/wasix/src/syscalls/wasi/path_filestat_set_times.rs
index 6a80c195667..328ceb995ef 100644
--- a/lib/wasix/src/syscalls/wasi/path_filestat_set_times.rs
+++ b/lib/wasix/src/syscalls/wasi/path_filestat_set_times.rs
@@ -67,7 +67,7 @@ pub fn path_filestat_set_times<M: MemorySize>(
         )
         .map_err(|err| {
             tracing::error!("failed to save file set times event - {}", err);
-            WasiError::Exit(ExitCode::Errno(Errno::Fault))
+            WasiError::Exit(ExitCode::from(Errno::Fault))
         })?;
     }
 
diff --git a/lib/wasix/src/syscalls/wasi/path_link.rs b/lib/wasix/src/syscalls/wasi/path_link.rs
index 3c0d645a235..aa7253c1485 100644
--- a/lib/wasix/src/syscalls/wasi/path_link.rs
+++ b/lib/wasix/src/syscalls/wasi/path_link.rs
@@ -61,7 +61,7 @@ pub fn path_link<M: MemorySize>(
         )
         .map_err(|err| {
             tracing::error!("failed to save path hard link event - {}", err);
-            WasiError::Exit(ExitCode::Errno(Errno::Fault))
+            WasiError::Exit(ExitCode::from(Errno::Fault))
         })?;
     }
 
diff --git a/lib/wasix/src/syscalls/wasi/path_open.rs b/lib/wasix/src/syscalls/wasi/path_open.rs
index 9c8d3c81655..759835beafa 100644
--- a/lib/wasix/src/syscalls/wasi/path_open.rs
+++ b/lib/wasix/src/syscalls/wasi/path_open.rs
@@ -99,7 +99,7 @@ pub fn path_open<M: MemorySize>(
         )
         .map_err(|err| {
             tracing::error!("failed to save unlink event - {}", err);
-            WasiError::Exit(ExitCode::Errno(Errno::Fault))
+            WasiError::Exit(ExitCode::from(Errno::Fault))
         })?;
     }
 
diff --git a/lib/wasix/src/syscalls/wasi/path_rename.rs b/lib/wasix/src/syscalls/wasi/path_rename.rs
index c334d6ff250..6e117c4dc70 100644
--- a/lib/wasix/src/syscalls/wasi/path_rename.rs
+++ b/lib/wasix/src/syscalls/wasi/path_rename.rs
@@ -44,7 +44,7 @@ pub fn path_rename<M: MemorySize>(
             JournalEffector::save_path_rename(&mut ctx, old_fd, source_str, new_fd, target_str)
                 .map_err(|err| {
                     tracing::error!("failed to save path rename event - {}", err);
-                    WasiError::Exit(ExitCode::Errno(Errno::Fault))
+                    WasiError::Exit(ExitCode::from(Errno::Fault))
                 })?;
         }
     }
diff --git a/lib/wasix/src/syscalls/wasi/path_symlink.rs b/lib/wasix/src/syscalls/wasi/path_symlink.rs
index 112e78fbdd5..dd995511d95 100644
--- a/lib/wasix/src/syscalls/wasi/path_symlink.rs
+++ b/lib/wasix/src/syscalls/wasi/path_symlink.rs
@@ -45,7 +45,7 @@ pub fn path_symlink<M: MemorySize>(
         JournalEffector::save_path_symlink(&mut ctx, old_path_str, fd, new_path_str).map_err(
             |err| {
                 tracing::error!("failed to save path symbolic link event - {}", err);
-                WasiError::Exit(ExitCode::Errno(Errno::Fault))
+                WasiError::Exit(ExitCode::from(Errno::Fault))
             },
         )?;
     }
diff --git a/lib/wasix/src/syscalls/wasix/chdir.rs b/lib/wasix/src/syscalls/wasix/chdir.rs
index 5c2d643139e..6fc6de3b277 100644
--- a/lib/wasix/src/syscalls/wasix/chdir.rs
+++ b/lib/wasix/src/syscalls/wasix/chdir.rs
@@ -21,7 +21,7 @@ pub fn chdir<M: MemorySize>(
     if env.enable_journal {
         JournalEffector::save_chdir(&mut ctx, path).map_err(|err| {
             tracing::error!("failed to chdir event - {}", err);
-            WasiError::Exit(ExitCode::Errno(Errno::Fault))
+            WasiError::Exit(ExitCode::from(Errno::Fault))
         })?;
     }
 
diff --git a/lib/wasix/src/syscalls/wasix/epoll_create.rs b/lib/wasix/src/syscalls/wasix/epoll_create.rs
index 91e63ea978d..0a42872f83e 100644
--- a/lib/wasix/src/syscalls/wasix/epoll_create.rs
+++ b/lib/wasix/src/syscalls/wasix/epoll_create.rs
@@ -25,7 +25,7 @@ pub fn epoll_create<M: MemorySize + 'static>(
     if env.enable_journal {
         JournalEffector::save_epoll_create(&mut ctx, fd).map_err(|err| {
             tracing::error!("failed to save epoll_create event - {}", err);
-            WasiError::Exit(ExitCode::Errno(Errno::Fault))
+            WasiError::Exit(ExitCode::from(Errno::Fault))
         })?;
     }
 
diff --git a/lib/wasix/src/syscalls/wasix/epoll_ctl.rs b/lib/wasix/src/syscalls/wasix/epoll_ctl.rs
index 06ff54159af..19e9fa9835e 100644
--- a/lib/wasix/src/syscalls/wasix/epoll_ctl.rs
+++ b/lib/wasix/src/syscalls/wasix/epoll_ctl.rs
@@ -64,7 +64,7 @@ pub fn epoll_ctl<M: MemorySize + 'static>(
     if env.enable_journal {
         JournalEffector::save_epoll_ctl(&mut ctx, epfd, op, fd, event_ctl).map_err(|err| {
             tracing::error!("failed to save epoll_create event - {}", err);
-            WasiError::Exit(ExitCode::Errno(Errno::Fault))
+            WasiError::Exit(ExitCode::from(Errno::Fault))
         })?;
     }
 
diff --git a/lib/wasix/src/syscalls/wasix/fd_pipe.rs b/lib/wasix/src/syscalls/wasix/fd_pipe.rs
index 2ca80e2fd27..741384b54c2 100644
--- a/lib/wasix/src/syscalls/wasix/fd_pipe.rs
+++ b/lib/wasix/src/syscalls/wasix/fd_pipe.rs
@@ -23,7 +23,7 @@ pub fn fd_pipe<M: MemorySize>(
     if env.enable_journal {
         JournalEffector::save_fd_pipe(&mut ctx, fd1, fd2).map_err(|err| {
             tracing::error!("failed to save create pipe event - {}", err);
-            WasiError::Exit(ExitCode::Errno(Errno::Fault))
+            WasiError::Exit(ExitCode::from(Errno::Fault))
         })?;
     }
 
diff --git a/lib/wasix/src/syscalls/wasix/port_addr_add.rs b/lib/wasix/src/syscalls/wasix/port_addr_add.rs
index aa3f4db83b9..8b62536893d 100644
--- a/lib/wasix/src/syscalls/wasix/port_addr_add.rs
+++ b/lib/wasix/src/syscalls/wasix/port_addr_add.rs
@@ -26,7 +26,7 @@ pub fn port_addr_add<M: MemorySize>(
     if ctx.data().enable_journal {
         JournalEffector::save_port_addr_add(&mut ctx, cidr).map_err(|err| {
             tracing::error!("failed to save port_addr_add event - {}", err);
-            WasiError::Exit(ExitCode::Errno(Errno::Fault))
+            WasiError::Exit(ExitCode::from(Errno::Fault))
         })?;
     }
 
diff --git a/lib/wasix/src/syscalls/wasix/port_addr_clear.rs b/lib/wasix/src/syscalls/wasix/port_addr_clear.rs
index e8959c62fab..a0e014bd5e1 100644
--- a/lib/wasix/src/syscalls/wasix/port_addr_clear.rs
+++ b/lib/wasix/src/syscalls/wasix/port_addr_clear.rs
@@ -11,7 +11,7 @@ pub fn port_addr_clear(mut ctx: FunctionEnvMut<'_, WasiEnv>) -> Result<Errno, Wa
     if ctx.data().enable_journal {
         JournalEffector::save_port_addr_clear(&mut ctx).map_err(|err| {
             tracing::error!("failed to save port_addr_clear event - {}", err);
-            WasiError::Exit(ExitCode::Errno(Errno::Fault))
+            WasiError::Exit(ExitCode::from(Errno::Fault))
         })?;
     }
 
diff --git a/lib/wasix/src/syscalls/wasix/port_addr_remove.rs b/lib/wasix/src/syscalls/wasix/port_addr_remove.rs
index 01466f0432f..62aab6d603c 100644
--- a/lib/wasix/src/syscalls/wasix/port_addr_remove.rs
+++ b/lib/wasix/src/syscalls/wasix/port_addr_remove.rs
@@ -24,7 +24,7 @@ pub fn port_addr_remove<M: MemorySize>(
     if ctx.data().enable_journal {
         JournalEffector::save_port_addr_remove(&mut ctx, ip).map_err(|err| {
             tracing::error!("failed to save port_addr_remove event - {}", err);
-            WasiError::Exit(ExitCode::Errno(Errno::Fault))
+            WasiError::Exit(ExitCode::from(Errno::Fault))
         })?;
     }
 
diff --git a/lib/wasix/src/syscalls/wasix/port_bridge.rs b/lib/wasix/src/syscalls/wasix/port_bridge.rs
index 6bd79e70e58..75dc59edcc4 100644
--- a/lib/wasix/src/syscalls/wasix/port_bridge.rs
+++ b/lib/wasix/src/syscalls/wasix/port_bridge.rs
@@ -44,7 +44,7 @@ pub fn port_bridge<M: MemorySize>(
     if ctx.data().enable_journal {
         JournalEffector::save_port_bridge(&mut ctx, network, token, security).map_err(|err| {
             tracing::error!("failed to save port_bridge event - {}", err);
-            WasiError::Exit(ExitCode::Errno(Errno::Fault))
+            WasiError::Exit(ExitCode::from(Errno::Fault))
         })?;
     }
 
diff --git a/lib/wasix/src/syscalls/wasix/port_dhcp_acquire.rs b/lib/wasix/src/syscalls/wasix/port_dhcp_acquire.rs
index e380ad2c541..a11cea1499e 100644
--- a/lib/wasix/src/syscalls/wasix/port_dhcp_acquire.rs
+++ b/lib/wasix/src/syscalls/wasix/port_dhcp_acquire.rs
@@ -11,7 +11,7 @@ pub fn port_dhcp_acquire(mut ctx: FunctionEnvMut<'_, WasiEnv>) -> Result<Errno,
     if ctx.data().enable_journal {
         JournalEffector::save_port_dhcp_acquire(&mut ctx).map_err(|err| {
             tracing::error!("failed to save port_dhcp_acquire event - {}", err);
-            WasiError::Exit(ExitCode::Errno(Errno::Fault))
+            WasiError::Exit(ExitCode::from(Errno::Fault))
         })?;
     }
 
diff --git a/lib/wasix/src/syscalls/wasix/port_gateway_set.rs b/lib/wasix/src/syscalls/wasix/port_gateway_set.rs
index b2bfc394350..6841577c4f9 100644
--- a/lib/wasix/src/syscalls/wasix/port_gateway_set.rs
+++ b/lib/wasix/src/syscalls/wasix/port_gateway_set.rs
@@ -24,7 +24,7 @@ pub fn port_gateway_set<M: MemorySize>(
     if ctx.data().enable_journal {
         JournalEffector::save_port_gateway_set(&mut ctx, ip).map_err(|err| {
             tracing::error!("failed to save port_gateway_set event - {}", err);
-            WasiError::Exit(ExitCode::Errno(Errno::Fault))
+            WasiError::Exit(ExitCode::from(Errno::Fault))
         })?;
     }
 
diff --git a/lib/wasix/src/syscalls/wasix/port_route_add.rs b/lib/wasix/src/syscalls/wasix/port_route_add.rs
index 0e2934aac74..80b909d977d 100644
--- a/lib/wasix/src/syscalls/wasix/port_route_add.rs
+++ b/lib/wasix/src/syscalls/wasix/port_route_add.rs
@@ -54,7 +54,7 @@ pub fn port_route_add<M: MemorySize>(
         )
         .map_err(|err| {
             tracing::error!("failed to save port_route_add event - {}", err);
-            WasiError::Exit(ExitCode::Errno(Errno::Fault))
+            WasiError::Exit(ExitCode::from(Errno::Fault))
         })?;
     }
 
diff --git a/lib/wasix/src/syscalls/wasix/port_route_clear.rs b/lib/wasix/src/syscalls/wasix/port_route_clear.rs
index f2d2de02cb4..5ccce508cc9 100644
--- a/lib/wasix/src/syscalls/wasix/port_route_clear.rs
+++ b/lib/wasix/src/syscalls/wasix/port_route_clear.rs
@@ -11,7 +11,7 @@ pub fn port_route_clear(mut ctx: FunctionEnvMut<'_, WasiEnv>) -> Result<Errno, W
     if ctx.data().enable_journal {
         JournalEffector::save_port_route_clear(&mut ctx).map_err(|err| {
             tracing::error!("failed to save port_route_clear event - {}", err);
-            WasiError::Exit(ExitCode::Errno(Errno::Fault))
+            WasiError::Exit(ExitCode::from(Errno::Fault))
         })?;
     }
 
diff --git a/lib/wasix/src/syscalls/wasix/port_route_remove.rs b/lib/wasix/src/syscalls/wasix/port_route_remove.rs
index 275d9ab5c8f..65fe602f702 100644
--- a/lib/wasix/src/syscalls/wasix/port_route_remove.rs
+++ b/lib/wasix/src/syscalls/wasix/port_route_remove.rs
@@ -20,7 +20,7 @@ pub fn port_route_remove<M: MemorySize>(
     if ctx.data().enable_journal {
         JournalEffector::save_port_route_remove(&mut ctx, ip).map_err(|err| {
             tracing::error!("failed to save port_route_remove event - {}", err);
-            WasiError::Exit(ExitCode::Errno(Errno::Fault))
+            WasiError::Exit(ExitCode::from(Errno::Fault))
         })?;
     }
 
diff --git a/lib/wasix/src/syscalls/wasix/port_unbridge.rs b/lib/wasix/src/syscalls/wasix/port_unbridge.rs
index c083511119b..53f0ff27787 100644
--- a/lib/wasix/src/syscalls/wasix/port_unbridge.rs
+++ b/lib/wasix/src/syscalls/wasix/port_unbridge.rs
@@ -11,7 +11,7 @@ pub fn port_unbridge(mut ctx: FunctionEnvMut<'_, WasiEnv>) -> Result<Errno, Wasi
     if ctx.data().enable_journal {
         JournalEffector::save_port_unbridge(&mut ctx).map_err(|err| {
             tracing::error!("failed to save port_unbridge event - {}", err);
-            WasiError::Exit(ExitCode::Errno(Errno::Fault))
+            WasiError::Exit(ExitCode::from(Errno::Fault))
         })?;
     }
 
diff --git a/lib/wasix/src/syscalls/wasix/sock_accept.rs b/lib/wasix/src/syscalls/wasix/sock_accept.rs
index 2ccbaa10086..dcf8c87bc31 100644
--- a/lib/wasix/src/syscalls/wasix/sock_accept.rs
+++ b/lib/wasix/src/syscalls/wasix/sock_accept.rs
@@ -93,7 +93,7 @@ pub fn sock_accept_v2<M: MemorySize>(
         )
         .map_err(|err| {
             tracing::error!("failed to save sock_accepted event - {}", err);
-            WasiError::Exit(ExitCode::Errno(Errno::Fault))
+            WasiError::Exit(ExitCode::from(Errno::Fault))
         })?;
     }
 
diff --git a/lib/wasix/src/syscalls/wasix/sock_bind.rs b/lib/wasix/src/syscalls/wasix/sock_bind.rs
index 561dabf3cd3..d4e31e81db5 100644
--- a/lib/wasix/src/syscalls/wasix/sock_bind.rs
+++ b/lib/wasix/src/syscalls/wasix/sock_bind.rs
@@ -28,7 +28,7 @@ pub fn sock_bind<M: MemorySize>(
     if ctx.data().enable_journal {
         JournalEffector::save_sock_bind(&mut ctx, sock, addr).map_err(|err| {
             tracing::error!("failed to save sock_bind event - {}", err);
-            WasiError::Exit(ExitCode::Errno(Errno::Fault))
+            WasiError::Exit(ExitCode::from(Errno::Fault))
         })?;
     }
 
diff --git a/lib/wasix/src/syscalls/wasix/sock_connect.rs b/lib/wasix/src/syscalls/wasix/sock_connect.rs
index 09c65fb62ff..c51dc55b38e 100644
--- a/lib/wasix/src/syscalls/wasix/sock_connect.rs
+++ b/lib/wasix/src/syscalls/wasix/sock_connect.rs
@@ -38,7 +38,7 @@ pub fn sock_connect<M: MemorySize>(
         JournalEffector::save_sock_connect(&mut ctx, sock, local_addr, peer_addr).map_err(
             |err| {
                 tracing::error!("failed to save sock_connected event - {}", err);
-                WasiError::Exit(ExitCode::Errno(Errno::Fault))
+                WasiError::Exit(ExitCode::from(Errno::Fault))
             },
         )?;
     }
diff --git a/lib/wasix/src/syscalls/wasix/sock_join_multicast_v4.rs b/lib/wasix/src/syscalls/wasix/sock_join_multicast_v4.rs
index 05aa022586b..5d3fd071c4e 100644
--- a/lib/wasix/src/syscalls/wasix/sock_join_multicast_v4.rs
+++ b/lib/wasix/src/syscalls/wasix/sock_join_multicast_v4.rs
@@ -30,7 +30,7 @@ pub fn sock_join_multicast_v4<M: MemorySize>(
         JournalEffector::save_sock_join_ipv4_multicast(&mut ctx, sock, multiaddr, iface).map_err(
             |err| {
                 tracing::error!("failed to save sock_join_ipv4_multicast event - {}", err);
-                WasiError::Exit(ExitCode::Errno(Errno::Fault))
+                WasiError::Exit(ExitCode::from(Errno::Fault))
             },
         )?;
     }
diff --git a/lib/wasix/src/syscalls/wasix/sock_join_multicast_v6.rs b/lib/wasix/src/syscalls/wasix/sock_join_multicast_v6.rs
index f70b827fb50..17a74859b93 100644
--- a/lib/wasix/src/syscalls/wasix/sock_join_multicast_v6.rs
+++ b/lib/wasix/src/syscalls/wasix/sock_join_multicast_v6.rs
@@ -29,7 +29,7 @@ pub fn sock_join_multicast_v6<M: MemorySize>(
         JournalEffector::save_sock_join_ipv6_multicast(&mut ctx, sock, multiaddr, iface).map_err(
             |err| {
                 tracing::error!("failed to save sock_join_ipv6_multicast event - {}", err);
-                WasiError::Exit(ExitCode::Errno(Errno::Fault))
+                WasiError::Exit(ExitCode::from(Errno::Fault))
             },
         )?;
     }
diff --git a/lib/wasix/src/syscalls/wasix/sock_leave_multicast_v4.rs b/lib/wasix/src/syscalls/wasix/sock_leave_multicast_v4.rs
index 12d58489cd0..aa8f30f923d 100644
--- a/lib/wasix/src/syscalls/wasix/sock_leave_multicast_v4.rs
+++ b/lib/wasix/src/syscalls/wasix/sock_leave_multicast_v4.rs
@@ -30,7 +30,7 @@ pub fn sock_leave_multicast_v4<M: MemorySize>(
         JournalEffector::save_sock_leave_ipv4_multicast(&mut ctx, sock, multiaddr, iface).map_err(
             |err| {
                 tracing::error!("failed to save sock_leave_ipv4_multicast event - {}", err);
-                WasiError::Exit(ExitCode::Errno(Errno::Fault))
+                WasiError::Exit(ExitCode::from(Errno::Fault))
             },
         )?;
     }
diff --git a/lib/wasix/src/syscalls/wasix/sock_leave_multicast_v6.rs b/lib/wasix/src/syscalls/wasix/sock_leave_multicast_v6.rs
index 33e7888ee03..f021f52e5ec 100644
--- a/lib/wasix/src/syscalls/wasix/sock_leave_multicast_v6.rs
+++ b/lib/wasix/src/syscalls/wasix/sock_leave_multicast_v6.rs
@@ -29,7 +29,7 @@ pub fn sock_leave_multicast_v6<M: MemorySize>(
         JournalEffector::save_sock_leave_ipv6_multicast(&mut ctx, sock, multiaddr, iface).map_err(
             |err| {
                 tracing::error!("failed to save sock_leave_ipv6_multicast event - {}", err);
-                WasiError::Exit(ExitCode::Errno(Errno::Fault))
+                WasiError::Exit(ExitCode::from(Errno::Fault))
             },
         )?;
     }
diff --git a/lib/wasix/src/syscalls/wasix/sock_listen.rs b/lib/wasix/src/syscalls/wasix/sock_listen.rs
index dace9bc0f5e..10cbf99a4fb 100644
--- a/lib/wasix/src/syscalls/wasix/sock_listen.rs
+++ b/lib/wasix/src/syscalls/wasix/sock_listen.rs
@@ -30,7 +30,7 @@ pub fn sock_listen<M: MemorySize>(
     if ctx.data().enable_journal {
         JournalEffector::save_sock_listen(&mut ctx, sock, backlog).map_err(|err| {
             tracing::error!("failed to save sock_listen event - {}", err);
-            WasiError::Exit(ExitCode::Errno(Errno::Fault))
+            WasiError::Exit(ExitCode::from(Errno::Fault))
         })?;
     }
 
diff --git a/lib/wasix/src/syscalls/wasix/sock_open.rs b/lib/wasix/src/syscalls/wasix/sock_open.rs
index 407b0f1cd63..19ba4cdf2ab 100644
--- a/lib/wasix/src/syscalls/wasix/sock_open.rs
+++ b/lib/wasix/src/syscalls/wasix/sock_open.rs
@@ -49,7 +49,7 @@ pub fn sock_open<M: MemorySize>(
     if ctx.data().enable_journal {
         JournalEffector::save_sock_open(&mut ctx, af, ty, pt, fd).map_err(|err| {
             tracing::error!("failed to save sock_open event - {}", err);
-            WasiError::Exit(ExitCode::Errno(Errno::Fault))
+            WasiError::Exit(ExitCode::from(Errno::Fault))
         })?;
     }
 
diff --git a/lib/wasix/src/syscalls/wasix/sock_send.rs b/lib/wasix/src/syscalls/wasix/sock_send.rs
index 00b543c50fe..c70a2f6be9e 100644
--- a/lib/wasix/src/syscalls/wasix/sock_send.rs
+++ b/lib/wasix/src/syscalls/wasix/sock_send.rs
@@ -70,7 +70,7 @@ pub fn sock_send<M: MemorySize>(
         JournalEffector::save_sock_send(&ctx, fd, bytes_written, si_data, si_data_len, si_flags)
             .map_err(|err| {
                 tracing::error!("failed to save sock_send event - {}", err);
-                WasiError::Exit(ExitCode::Errno(Errno::Fault))
+                WasiError::Exit(ExitCode::from(Errno::Fault))
             })?;
     }
 
diff --git a/lib/wasix/src/syscalls/wasix/sock_send_file.rs b/lib/wasix/src/syscalls/wasix/sock_send_file.rs
index 14dd2e5866b..50581fbb290 100644
--- a/lib/wasix/src/syscalls/wasix/sock_send_file.rs
+++ b/lib/wasix/src/syscalls/wasix/sock_send_file.rs
@@ -35,7 +35,7 @@ pub fn sock_send_file<M: MemorySize>(
         JournalEffector::save_sock_send_file::<M>(&mut ctx, sock, in_fd, offset, total_written)
             .map_err(|err| {
                 tracing::error!("failed to save sock_send_file event - {}", err);
-                WasiError::Exit(ExitCode::Errno(Errno::Fault))
+                WasiError::Exit(ExitCode::from(Errno::Fault))
             })?;
     }
 
diff --git a/lib/wasix/src/syscalls/wasix/sock_send_to.rs b/lib/wasix/src/syscalls/wasix/sock_send_to.rs
index ad70e22c6a3..7b314c8814e 100644
--- a/lib/wasix/src/syscalls/wasix/sock_send_to.rs
+++ b/lib/wasix/src/syscalls/wasix/sock_send_to.rs
@@ -62,7 +62,7 @@ pub fn sock_send_to<M: MemorySize>(
         )
         .map_err(|err| {
             tracing::error!("failed to save sock_send_to event - {}", err);
-            WasiError::Exit(ExitCode::Errno(Errno::Fault))
+            WasiError::Exit(ExitCode::from(Errno::Fault))
         })?;
     }
 
diff --git a/lib/wasix/src/syscalls/wasix/sock_set_opt_flag.rs b/lib/wasix/src/syscalls/wasix/sock_set_opt_flag.rs
index ef0d78cb347..c552fb2b5f3 100644
--- a/lib/wasix/src/syscalls/wasix/sock_set_opt_flag.rs
+++ b/lib/wasix/src/syscalls/wasix/sock_set_opt_flag.rs
@@ -29,7 +29,7 @@ pub fn sock_set_opt_flag(
     if ctx.data().enable_journal {
         JournalEffector::save_sock_set_opt_flag(&mut ctx, sock, opt, flag).map_err(|err| {
             tracing::error!("failed to save sock_set_opt_flag event - {}", err);
-            WasiError::Exit(ExitCode::Errno(Errno::Fault))
+            WasiError::Exit(ExitCode::from(Errno::Fault))
         })?;
     }
 
diff --git a/lib/wasix/src/syscalls/wasix/sock_set_opt_size.rs b/lib/wasix/src/syscalls/wasix/sock_set_opt_size.rs
index 73e8a1fd312..9d2bc3e86f5 100644
--- a/lib/wasix/src/syscalls/wasix/sock_set_opt_size.rs
+++ b/lib/wasix/src/syscalls/wasix/sock_set_opt_size.rs
@@ -23,7 +23,7 @@ pub fn sock_set_opt_size(
     if ctx.data().enable_journal {
         JournalEffector::save_sock_set_opt_size(&mut ctx, sock, opt, size).map_err(|err| {
             tracing::error!("failed to save sock_set_opt_size event - {}", err);
-            WasiError::Exit(ExitCode::Errno(Errno::Fault))
+            WasiError::Exit(ExitCode::from(Errno::Fault))
         })?;
     }
 
diff --git a/lib/wasix/src/syscalls/wasix/sock_set_opt_time.rs b/lib/wasix/src/syscalls/wasix/sock_set_opt_time.rs
index d4d1af84996..dececec26ed 100644
--- a/lib/wasix/src/syscalls/wasix/sock_set_opt_time.rs
+++ b/lib/wasix/src/syscalls/wasix/sock_set_opt_time.rs
@@ -41,7 +41,7 @@ pub fn sock_set_opt_time<M: MemorySize>(
     if ctx.data().enable_journal {
         JournalEffector::save_sock_set_opt_time(&mut ctx, sock, ty, time).map_err(|err| {
             tracing::error!("failed to save sock_set_opt_time event - {}", err);
-            WasiError::Exit(ExitCode::Errno(Errno::Fault))
+            WasiError::Exit(ExitCode::from(Errno::Fault))
         })?;
     }
 
diff --git a/lib/wasix/src/syscalls/wasix/sock_shutdown.rs b/lib/wasix/src/syscalls/wasix/sock_shutdown.rs
index 2c1cc72516f..bd8b84cf573 100644
--- a/lib/wasix/src/syscalls/wasix/sock_shutdown.rs
+++ b/lib/wasix/src/syscalls/wasix/sock_shutdown.rs
@@ -30,7 +30,7 @@ pub fn sock_shutdown(
     if ctx.data().enable_journal {
         JournalEffector::save_sock_shutdown(&mut ctx, sock, shutdown).map_err(|err| {
             tracing::error!("failed to save sock_shutdown event - {}", err);
-            WasiError::Exit(ExitCode::Errno(Errno::Fault))
+            WasiError::Exit(ExitCode::from(Errno::Fault))
         })?;
     }
 
diff --git a/lib/wasix/src/syscalls/wasix/thread_join.rs b/lib/wasix/src/syscalls/wasix/thread_join.rs
index 511e5d0e47b..4142d187899 100644
--- a/lib/wasix/src/syscalls/wasix/thread_join.rs
+++ b/lib/wasix/src/syscalls/wasix/thread_join.rs
@@ -37,10 +37,7 @@ pub(super) fn thread_join_internal<M: MemorySize + 'static>(
             other_thread
                 .join()
                 .await
-                .map_err(|err| {
-                    err.as_exit_code()
-                        .unwrap_or(ExitCode::Errno(Errno::Unknown))
-                })
+                .map_err(|err| err.as_exit_code().unwrap_or(ExitCode::from(Errno::Unknown)))
                 .unwrap_or_else(|a| a)
                 .raw()
         })?;
diff --git a/lib/wasix/src/syscalls/wasix/tty_set.rs b/lib/wasix/src/syscalls/wasix/tty_set.rs
index 6738b09a23b..4110e01e01d 100644
--- a/lib/wasix/src/syscalls/wasix/tty_set.rs
+++ b/lib/wasix/src/syscalls/wasix/tty_set.rs
@@ -44,7 +44,7 @@ pub fn tty_set<M: MemorySize>(
     if env.enable_journal {
         JournalEffector::save_tty_set(&mut ctx, state).map_err(|err| {
             tracing::error!("failed to save path symbolic link event - {}", err);
-            WasiError::Exit(ExitCode::Errno(Errno::Fault))
+            WasiError::Exit(ExitCode::from(Errno::Fault))
         })?;
     }
 


Test patch:
diff --git a/lib/journal/src/concrete/tests.rs b/lib/journal/src/concrete/tests.rs
index 0a5d9395d3b..3ce836ce35e 100644
--- a/lib/journal/src/concrete/tests.rs
+++ b/lib/journal/src/concrete/tests.rs
@@ -63,7 +63,7 @@ pub fn test_record_init_module() {
 #[test]
 pub fn test_record_process_exit() {
     run_test(JournalEntry::ProcessExitV1 {
-        exit_code: Some(wasi::ExitCode::Errno(wasi::Errno::Fault)),
+        exit_code: Some(wasi::ExitCode::from(wasi::Errno::Fault)),
     });
 }
 
@@ -91,7 +91,7 @@ pub fn test_record_set_thread() {
 pub fn test_record_close_thread() {
     run_test(JournalEntry::CloseThreadV1 {
         id: 987u32,
-        exit_code: Some(wasi::ExitCode::Errno(wasi::Errno::Fault)),
+        exit_code: Some(wasi::ExitCode::from(wasi::Errno::Fault)),
     });
 }