mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 01:15:14 +02:00
Refactor: Construct IoError
from std::io::Error
instead of std::io::ErrorKind
(#15777)
This commit is contained in:
@ -87,7 +87,7 @@ impl CommunicationMode {
|
||||
.and_then(|name| ListenerOptions::new().name(name).create_sync())
|
||||
.map_err(|err| {
|
||||
IoError::new_internal(
|
||||
err.kind(),
|
||||
err,
|
||||
format!(
|
||||
"Could not interpret local socket name {:?}",
|
||||
name.to_string_lossy()
|
||||
@ -117,7 +117,7 @@ impl CommunicationMode {
|
||||
.and_then(|name| ls::Stream::connect(name))
|
||||
.map_err(|err| {
|
||||
ShellError::Io(IoError::new_internal(
|
||||
err.kind(),
|
||||
err,
|
||||
format!(
|
||||
"Could not interpret local socket name {:?}",
|
||||
name.to_string_lossy()
|
||||
@ -190,7 +190,7 @@ impl PreparedServerCommunication {
|
||||
.set_nonblocking(ListenerNonblockingMode::Accept)
|
||||
.map_err(|err| {
|
||||
IoError::new_internal(
|
||||
err.kind(),
|
||||
err,
|
||||
"Could not set non-blocking mode accept for listener",
|
||||
nu_protocol::location!(),
|
||||
)
|
||||
@ -204,7 +204,7 @@ impl PreparedServerCommunication {
|
||||
// good measure. Had an issue without this on macOS.
|
||||
stream.set_nonblocking(false).map_err(|err| {
|
||||
IoError::new_internal(
|
||||
err.kind(),
|
||||
err,
|
||||
"Could not disable non-blocking mode for listener",
|
||||
nu_protocol::location!(),
|
||||
)
|
||||
@ -217,7 +217,7 @@ impl PreparedServerCommunication {
|
||||
// `WouldBlock` is ok, just means it's not ready yet, but some other
|
||||
// kind of error should be reported
|
||||
return Err(ShellError::Io(IoError::new_internal(
|
||||
err.kind(),
|
||||
err,
|
||||
"Accepting new data from listener failed",
|
||||
nu_protocol::location!(),
|
||||
)));
|
||||
|
@ -82,7 +82,7 @@ where
|
||||
fn flush(&self) -> Result<(), ShellError> {
|
||||
self.0.lock().flush().map_err(|err| {
|
||||
ShellError::Io(IoError::new_internal(
|
||||
err.kind(),
|
||||
err,
|
||||
"PluginWrite could not flush",
|
||||
nu_protocol::location!(),
|
||||
))
|
||||
@ -112,7 +112,7 @@ where
|
||||
})?;
|
||||
lock.flush().map_err(|err| {
|
||||
ShellError::Io(IoError::new_internal(
|
||||
err.kind(),
|
||||
err,
|
||||
"PluginWrite could not flush",
|
||||
nu_protocol::location!(),
|
||||
))
|
||||
@ -340,7 +340,7 @@ where
|
||||
writer.write_all(std::iter::from_fn(move || match reader.read(buf) {
|
||||
Ok(0) => None,
|
||||
Ok(len) => Some(Ok(buf[..len].to_vec())),
|
||||
Err(err) => Some(Err(ShellError::from(IoError::new(err.kind(), span, None)))),
|
||||
Err(err) => Some(Err(ShellError::from(IoError::new(err, span, None)))),
|
||||
}))?;
|
||||
Ok(())
|
||||
}
|
||||
@ -368,7 +368,7 @@ where
|
||||
})
|
||||
.map_err(|err| {
|
||||
IoError::new_internal(
|
||||
err.kind(),
|
||||
err,
|
||||
"Could not spawn plugin stream background writer",
|
||||
nu_protocol::location!(),
|
||||
)
|
||||
|
@ -246,7 +246,7 @@ fn read_pipeline_data_byte_stream() -> Result<(), ShellError> {
|
||||
ByteStreamSource::Read(mut read) => {
|
||||
let mut buf = Vec::new();
|
||||
read.read_to_end(&mut buf)
|
||||
.map_err(|err| IoError::new(err.kind(), test_span, None))?;
|
||||
.map_err(|err| IoError::new(err, test_span, None))?;
|
||||
let iter = buf.chunks_exact(out_pattern.len());
|
||||
assert_eq!(iter.len(), iterations);
|
||||
for chunk in iter {
|
||||
|
@ -1,5 +1,8 @@
|
||||
use nu_plugin_protocol::{PluginInput, PluginOutput};
|
||||
use nu_protocol::{ShellError, location, shell_error::io::IoError};
|
||||
use nu_protocol::{
|
||||
ShellError, location,
|
||||
shell_error::{self, io::IoError},
|
||||
};
|
||||
use serde::Deserialize;
|
||||
|
||||
use crate::{Encoder, PluginEncoder};
|
||||
@ -28,7 +31,7 @@ impl Encoder<PluginInput> for JsonSerializer {
|
||||
serde_json::to_writer(&mut *writer, plugin_input).map_err(json_encode_err)?;
|
||||
writer.write_all(b"\n").map_err(|err| {
|
||||
ShellError::Io(IoError::new_internal(
|
||||
err.kind(),
|
||||
err,
|
||||
"Failed to write final line break",
|
||||
location!(),
|
||||
))
|
||||
@ -55,7 +58,7 @@ impl Encoder<PluginOutput> for JsonSerializer {
|
||||
serde_json::to_writer(&mut *writer, plugin_output).map_err(json_encode_err)?;
|
||||
writer.write_all(b"\n").map_err(|err| {
|
||||
ShellError::Io(IoError::new_internal(
|
||||
err.kind(),
|
||||
err,
|
||||
"JsonSerializer could not encode linebreak",
|
||||
nu_protocol::location!(),
|
||||
))
|
||||
@ -77,7 +80,7 @@ impl Encoder<PluginOutput> for JsonSerializer {
|
||||
fn json_encode_err(err: serde_json::Error) -> ShellError {
|
||||
if err.is_io() {
|
||||
ShellError::Io(IoError::new_internal(
|
||||
err.io_error_kind().expect("is io"),
|
||||
shell_error::io::ErrorKind::from_std(err.io_error_kind().expect("is io")),
|
||||
"Could not encode with json",
|
||||
nu_protocol::location!(),
|
||||
))
|
||||
@ -94,7 +97,7 @@ fn json_decode_err<T>(err: serde_json::Error) -> Result<Option<T>, ShellError> {
|
||||
Ok(None)
|
||||
} else if err.is_io() {
|
||||
Err(ShellError::Io(IoError::new_internal(
|
||||
err.io_error_kind().expect("is io"),
|
||||
shell_error::io::ErrorKind::from_std(err.io_error_kind().expect("is io")),
|
||||
"Could not decode with json",
|
||||
nu_protocol::location!(),
|
||||
)))
|
||||
|
@ -1,7 +1,10 @@
|
||||
use std::io::ErrorKind;
|
||||
|
||||
use nu_plugin_protocol::{PluginInput, PluginOutput};
|
||||
use nu_protocol::{ShellError, shell_error::io::IoError};
|
||||
use nu_protocol::{
|
||||
ShellError,
|
||||
shell_error::{self, io::IoError},
|
||||
};
|
||||
use serde::Deserialize;
|
||||
|
||||
use crate::{Encoder, PluginEncoder};
|
||||
@ -66,7 +69,7 @@ fn rmp_encode_err(err: rmp_serde::encode::Error) -> ShellError {
|
||||
// I/O error
|
||||
ShellError::Io(IoError::new_internal(
|
||||
// TODO: get a better kind here
|
||||
std::io::ErrorKind::Other,
|
||||
shell_error::io::ErrorKind::from_std(std::io::ErrorKind::Other),
|
||||
"Could not encode with rmp",
|
||||
nu_protocol::location!(),
|
||||
))
|
||||
@ -92,7 +95,7 @@ fn rmp_decode_err<T>(err: rmp_serde::decode::Error) -> Result<Option<T>, ShellEr
|
||||
// I/O error
|
||||
Err(ShellError::Io(IoError::new_internal(
|
||||
// TODO: get a better kind here
|
||||
std::io::ErrorKind::Other,
|
||||
shell_error::io::ErrorKind::from_std(std::io::ErrorKind::Other),
|
||||
"Could not decode with rmp",
|
||||
nu_protocol::location!(),
|
||||
)))
|
||||
|
@ -379,7 +379,7 @@ macro_rules! generate_tests {
|
||||
.with_help("some help")
|
||||
.with_label("msg", Span::new(2, 30))
|
||||
.with_inner(ShellError::Io(IoError::new(
|
||||
std::io::ErrorKind::NotFound,
|
||||
shell_error::io::ErrorKind::from_std(std::io::ErrorKind::NotFound),
|
||||
Span::test_data(),
|
||||
None,
|
||||
)));
|
||||
|
Reference in New Issue
Block a user