Skip to content

Commit

Permalink
refactor: variant ReplEvent::Error
Browse files Browse the repository at this point in the history
Co-authored-by: Shahar "Dawn" Or <[email protected]>
  • Loading branch information
warren2k and mightyiam committed Jun 8, 2024
1 parent 4fb81e5 commit 633b738
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/app/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ impl State {
ReplEvent::Query(id, query, result) => self.repl_event_query(id, query, result),
ReplEvent::Kill(id) => self.repl_event_kill(id),
ReplEvent::Read(id, result) => self.repl_event_read(id, result),
ReplEvent::Error(error) => Err(error.into()),
}
}

Expand Down Expand Up @@ -124,11 +125,10 @@ impl State {
fn repl_event_read(
&mut self,
id: ExampleId,
result: std::io::Result<u8>,
ch: u8,
) -> anyhow::Result<Vec<OutputEvent>> {
let session_live = self.examples.get_mut_repl(&id)?;
let session_live = session_live.state.live_mut()?;
let ch = result?;

let output = match &mut session_live.expecting {
ReplSessionExpecting::Nothing => anyhow::bail!("not expecting, got {:?}", ch as char),
Expand Down
7 changes: 4 additions & 3 deletions src/repl/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ pub(crate) enum ReplEvent {
Spawn(pty_process::Result<ExampleId>),
Query(ExampleId, ReplQuery, anyhow::Result<()>),
Kill(anyhow::Result<ExampleId>),
Read(ExampleId, std::io::Result<u8>),
Read(ExampleId, u8),
Error(std::io::Error),
}

pub(crate) struct ReplDriver {
Expand Down Expand Up @@ -102,13 +103,13 @@ impl ReplDriver {
match byte {
Ok(byte) => {
self.sender
.send(ReplEvent::Read(id.clone(), Ok(byte)))
.send(ReplEvent::Read(id.clone(), byte))
.await
.unwrap();
}
Err(error) => {
self.sender
.send(ReplEvent::Read(id.clone(), Err(error)))
.send(ReplEvent::Error(error))
.await
.unwrap();
}
Expand Down

0 comments on commit 633b738

Please sign in to comment.