aatxe / irc

the irc crate – usable, async IRC for Rust
Mozilla Public License 2.0
528 stars 97 forks source link

[SOLVED] Config can be found, but IrcClient fails upon initializing #114

Closed ghost closed 6 years ago

ghost commented 6 years ago

SOLUTION

Removing cert_path from Config.toml solves everything!

Head -> Wall... sorry

IGNORE ALL BELOW.

Hey,

consider the following config in conf/config.toml

owners = []
nickname = "JustABot"
nick_password = ""
alt_nicks = []
username = "JustABot"
realname = "Just a bot"
server = "irc.freenode.net"
port = 6697
password = ""
use_ssl = true
cert_path = "cert.der"
encoding = "UTF-8"
channels = ["#bot-testing-area"]
umodes = "+RB-x"
user_info = "Get off my back, big brother!"
version = "irc:git:Rust"
source = "https://github.com/aatxe/irc"
ping_time = 180
ping_timeout = 10
burst_window_length = 8
max_messages_in_burst = 15
should_ghost = false
ghost_sequence = []

[channel_keys]
"#fake" = "password" 

Now I tried to read that config via:

let client: IrcClient::new("./conf/config.toml").unwrap() but got a nasty

thread 'main' panicked at 'called Result::unwrap() on an Err value: OneShotCanceled(Canceled)', libcore/result

Then I tried it "manually", like so:

let config = match Config::load("./conf/config.toml") {
        Ok(c) => c,
        Err(e) => panic!("Cannot find path: {:?}", e)
    };

    println!("Config is {:?}", config);

    let client = IrcClient::from_config(config).unwrap();

This does print the config, but fails again at the line: let client = IrcClient::from_config(config).unwrap();

with

thread 'main' panicked at 'called Result::unwrap() on an Err value: OneShotCanceled(Canceled)', libcore/result

Any ideas what's going wrong here?

The whole stacktrace tells me no more interesting story:

 stack backtrace:
   0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
             at libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
   1: std::sys_common::backtrace::print
             at libstd/sys_common/backtrace.rs:71
             at libstd/sys_common/backtrace.rs:59
   2: std::panicking::default_hook::{{closure}}
             at libstd/panicking.rs:380
   3: std::panicking::default_hook
             at libstd/panicking.rs:396
   4: std::panicking::rust_panic_with_hook
             at libstd/panicking.rs:576
   5: std::panicking::begin_panic
             at libstd/panicking.rs:537
   6: std::panicking::begin_panic_fmt
             at libstd/panicking.rs:521
   7: rust_begin_unwind
             at libstd/panicking.rs:497
   8: core::panicking::panic_fmt
             at libcore/panicking.rs:71
   9: core::result::unwrap_failed
             at /checkout/src/libcore/macros.rs:23
  10: <core::result::Result<T, E>>::unwrap
             at /checkout/src/libcore/result.rs:782
  11: testbot::main
             at src/main.rs:15
  12: std::rt::lang_start::{{closure}}
             at /checkout/src/libstd/rt.rs:74
  13: std::panicking::try::do_call
             at libstd/rt.rs:59
             at libstd/panicking.rs:479
  14: __rust_maybe_catch_panic
             at libpanic_unwind/lib.rs:102
  15: std::rt::lang_start_internal
             at libstd/panicking.rs:458
             at libstd/panic.rs:358
             at libstd/rt.rs:58
  16: std::rt::lang_start
             at /checkout/src/libstd/rt.rs:74
  17: main
  18: __libc_start_main
  19: _start

(Line 15 being this one let client = IrcClient::from_config(config).unwrap();)

I used the config from https://github.com/aatxe/irc main/readme-page

Also please note!

I only have that in my Cargo.toml irc = "0.13"

What I mean is, that on the main github page it says:

The default configuration format is TOML, though there is optional support for JSON and YAML via the optional json and yaml features.

While in the code (config.rs) it says:

/// Loads a configuration from the desired path. This will use the file extension to detect /// which format to parse the file as (json, toml, or yaml). Using each format requires having /// its respective crate feature enabled. Only json is available by default.

Last sentence being Only json is available by default.

for pub fn load<P: AsRef<Path>>(path: P) -> Result<Config> {

So is TOML available by default or must I use JSON and enable TOML by some feature?

aatxe commented 6 years ago

To answer the question at the end, TOML is enabled by default, not JSON. That comment is a holdover from days past. I will correct it.

To the point: I don't recommend actually using that whole big config. It's just a concise way of showing all the fields. You should indeed not try to add certificates that don't exist. That would be bad.

aatxe commented 6 years ago

There's also a side problem here which is that the error produced is confusing (it's not clear without looking at the implementation why you're getting a channel error). You can avoid this and get better error messages by using IrcReactor (look at reactor.rs for a version of simple.rs with IrcReactor).

This error using IrcReactor (and it'll be even nicer if you use Display on the error (chain) instead):

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Io(Error { repr: Os { code: 2, message: "No such file or directory" } })', src/libcore/result.rs:906:4
stack backtrace:
   0: std::sys::imp::backtrace::tracing::imp::unwind_backtrace
             at src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
   1: std::sys_common::backtrace::_print
             at src/libstd/sys_common/backtrace.rs:69
   2: std::panicking::default_hook::{{closure}}
             at src/libstd/sys_common/backtrace.rs:58
             at src/libstd/panicking.rs:381
   3: std::panicking::default_hook
             at src/libstd/panicking.rs:397
   4: std::panicking::begin_panic
             at src/libstd/panicking.rs:577
   5: std::panicking::begin_panic
             at src/libstd/panicking.rs:538
   6: std::panicking::try::do_call
             at src/libstd/panicking.rs:522
   7: std::panicking::try::do_call
             at src/libstd/panicking.rs:498
   8: <core::ops::range::Range<Idx> as core::fmt::Debug>::fmt
             at src/libcore/panicking.rs:71
   9: core::result::unwrap_failed
             at /Users/travis/build/rust-lang/rust/src/libcore/macros.rs:23
  10: <core::result::Result<T, E>>::unwrap
             at /Users/travis/build/rust-lang/rust/src/libcore/result.rs:772
  11: reactor::main
             at examples/reactor.rs:19
  12: panic_unwind::dwarf::eh::read_encoded_pointer
             at src/libpanic_unwind/lib.rs:99
  13: <std::rand::reader::ReaderRng<R> as rand::Rng>::fill_bytes
             at src/libstd/panicking.rs:459
             at src/libstd/panic.rs:361
             at src/libstd/rt.rs:59
  14: reactor::main::{{closure}}

Edit: I'll also be going through and adding more context with failure so that errors like this will specify, for example, what file was involved.