From e8c01ddef1a02c583e7e9fa031f424fcedd0aa4f Mon Sep 17 00:00:00 2001 From: Pat Hickey Date: Wed, 19 Aug 2020 14:29:14 -0700 Subject: [PATCH] put getrandom::Error into Error --- crates/wasi-common/src/error.rs | 2 ++ .../wasi-common/src/snapshots/wasi_snapshot_preview1.rs | 8 +++----- crates/wasi-common/src/wasi.rs | 1 + 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/crates/wasi-common/src/error.rs b/crates/wasi-common/src/error.rs index 074a61de48..282a46734f 100644 --- a/crates/wasi-common/src/error.rs +++ b/crates/wasi-common/src/error.rs @@ -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 diff --git a/crates/wasi-common/src/snapshots/wasi_snapshot_preview1.rs b/crates/wasi-common/src/snapshots/wasi_snapshot_preview1.rs index 9f2eaa1443..4c4034aa8a 100644 --- a/crates/wasi-common/src/snapshots/wasi_snapshot_preview1.rs +++ b/crates/wasi-common/src/snapshots/wasi_snapshot_preview1.rs @@ -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, 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( diff --git a/crates/wasi-common/src/wasi.rs b/crates/wasi-common/src/wasi.rs index ca4b5bd3fe..4903a672be 100644 --- a/crates/wasi-common/src/wasi.rs +++ b/crates/wasi-common/src/wasi.rs @@ -36,6 +36,7 @@ impl From 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,