put getrandom::Error into Error

This commit is contained in:
Pat Hickey
2020-08-19 14:29:14 -07:00
parent c1aec81b84
commit e8c01ddef1
3 changed files with 6 additions and 5 deletions

View File

@@ -14,6 +14,8 @@ pub enum Error {
TryFromInt(#[from] std::num::TryFromIntError),
#[error("Utf8Error: {0}")]
Utf8(#[from] std::str::Utf8Error),
#[error("GetRandom: {0}")]
GetRandom(#[from] getrandom::Error),
/// The host OS may return an io error that doesn't match one of the
/// wasi errno variants we expect. We do not expose the details of this

View File

@@ -5,7 +5,7 @@ use crate::wasi::wasi_snapshot_preview1::WasiSnapshotPreview1;
use crate::wasi::{types, AsBytes};
use crate::{path, poll};
use crate::{Error, Result, WasiCtx};
use log::{debug, error, trace};
use log::{debug, trace};
use std::convert::TryInto;
use std::io::{self, SeekFrom};
use wiggle::{GuestPtr, GuestSlice};
@@ -802,10 +802,8 @@ impl<'a> WasiSnapshotPreview1 for WasiCtx {
fn random_get(&self, buf: &GuestPtr<u8>, buf_len: types::Size) -> Result<()> {
let mut slice = buf.as_array(buf_len).as_slice()?;
getrandom::getrandom(&mut *slice).map_err(|err| {
error!("getrandom failure: {:?}", err);
Error::Io
})
getrandom::getrandom(&mut *slice)?;
Ok(())
}
fn sock_recv(

View File

@@ -36,6 +36,7 @@ impl From<Error> for Errno {
Error::TryFromInt(_) => Errno::Overflow,
Error::Utf8(_) => Errno::Ilseq,
Error::UnexpectedIo(_) => Errno::Io,
Error::GetRandom(_) => Errno::Io,
Error::TooBig => Errno::TooBig,
Error::Acces => Errno::Acces,
Error::Badf => Errno::Badf,