rexpect icon indicating copy to clipboard operation
rexpect copied to clipboard

WIP: Modernize error handling. Use crate thiserror and derive for error.

Open BeldrothTheGold opened this issue 5 years ago • 3 comments

The purpose of this PR is to modernize the error handling in rexpect. This PR removes crate error_chain in favor of thiserror. The primary benefit being that the library works seamlessly with the anyhow crate.

https://docs.rs/anyhow/1.0.33/anyhow/ https://docs.rs/thiserror/1.0.21/thiserror/

I tried to make as few API changes as necessary.

I did take this opportunity to create a few additional types of errors. Though only where it seemed a good idea.

PtyError,                            <-- nix::Errors, system issues from the PtyProcess
IOError,                             <-- std::id::Errors, an issue communicating with PtyProcess  #[from] std::io::Error 
UnknownControlChar,                  <-- self explanatory
RegexError,                          <-- self explanatory

I also updated the documentation where relevant.

Tests run successfully.

$ cargo test
   Compiling rexpect v0.4.0 (/home/scott/dev/rust/github/BeldrothTheGold/rexpect)

    Finished test [unoptimized + debuginfo] target(s) in 3.76s
     Running target/debug/deps/rexpect-dd009e9664b7fee9

running 18 tests
test session::tests::test_expect_empty_command_error ... ok
test reader::tests::test_regex2 ... ok
test reader::tests::test_regex ... ok
test reader::tests::test_nbytes ... ok
test reader::tests::test_eof ... ok
test reader::tests::test_try_read ... ok
test reader::tests::test_expect_melon ... ok
test session::tests::test_tokenize_command ... ok
test process::tests::test_cat ... ok
test session::tests::test_expect_any ... ok
test session::tests::test_read_string_before ... ok
test session::tests::test_read_line ... ok
test session::tests::test_expect_string ... ok
test session::tests::test_bash ... ok
test session::tests::test_bash_control_chars ... ok
test session::tests::test_expect_eof_timeout2 ... ok
test session::tests::test_expect_eof_timeout ... ok
test session::tests::test_kill_timeout ... ok

test result: ok. 18 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

   Doc-tests rexpect

running 8 tests
test src/lib.rs - (line 55) ... ok
test src/lib.rs - (line 17) ... ok
test src/process.rs - process::PtyProcess::status (line 155) ... ok
test src/process.rs - process::PtyProcess (line 28) ... ok
test src/reader.rs - reader::NBReader::read_until (line 207) ... ok
test src/session.rs - session::StreamSession<W>::exp_any (line 163) ... ok
test src/session.rs - session::PtySession (line 207) ... ok
test src/session.rs - session::PtyReplSession::execute (line 326) ... ok

test result: ok. 8 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

Let me know what you think.

BeldrothTheGold avatar Oct 16 '20 04:10 BeldrothTheGold

@BeldrothTheGold I've seen this PR but I currently have not enough time to keep up with this project. What was the reason for you to close this PR?

philippkeller avatar Oct 26 '20 06:10 philippkeller

@BeldrothTheGold I've seen this PR but I currently have not enough time to keep up with this project. What was the reason for you to close this PR?

@philippkeller Sorry for closing the PR. This is one of the first PRs I have submitted to an open source project. Definitely the first for a rust project.

A change of the Error types and error dependencies of the library seem like a pretty major change.

Also, I am not sure if we want to use non_exhaustive on the Error enum or not.

  • I figured since this change was breaking anyway, it could be added if we want.

BeldrothTheGold avatar Nov 05 '20 04:11 BeldrothTheGold

Hi, I have a test using https://github.com/BeldrothTheGold/rexpect/tree/fromerror, it can work. Hope the PR can be merged.

alienzj avatar Apr 21 '21 14:04 alienzj

Hi! I am closing this PR now as it seems to be no longer relevant to you. Feel free to open a new one if you're still running into issues!

Also, error-chain was replaced in #58 !

matthiasbeyer avatar Sep 12 '22 11:09 matthiasbeyer