Initial error refactor

This commit is contained in:
Marcin Mielniczuk
2019-09-07 19:36:29 +02:00
committed by Jakub Konka
parent 85a41d449c
commit 14aaffd46f
22 changed files with 560 additions and 383 deletions

View File

@@ -1,10 +1,10 @@
use crate::{host, Result};
use crate::{Error, Result};
use std::convert::TryInto;
use std::time::{SystemTime, UNIX_EPOCH};
pub(crate) fn systemtime_to_timestamp(st: SystemTime) -> Result<u64> {
st.duration_since(UNIX_EPOCH)
.map_err(|_| host::__WASI_EINVAL)? // date earlier than UNIX_EPOCH
.map_err(|_| Error::EINVAL)? // date earlier than UNIX_EPOCH
.as_nanos()
.try_into()
.map_err(|_| host::__WASI_EOVERFLOW) // u128 doesn't fit into u64
.map_err(|_| Error::EOVERFLOW) // u128 doesn't fit into u64
}