生锈时运行错误:索引超出范围:len为0但索引为0

时间:2016-10-13 12:30:15

标签: curl rust runtime-error

我使用rust-slack并遇到了运行时错误,对于像我这样的初学者来说这很难理解:

thread 'main' panicked at 'index out of bounds: the len is 0 but the index is 0', ../src/libcollections/vec.rs:1265
stack backtrace:
   1:     0x55c042e567e9 - std::sys::backtrace::tracing::imp::write::h00e948915d1e4c72
   2:     0x55c042e5d9fc - std::panicking::default_hook::_{{closure}}::h7b8a142818383fb8
   3:     0x55c042e5cc49 - std::panicking::default_hook::h41cf296f654245d7
   4:     0x55c042e5d338 - std::panicking::rust_panic_with_hook::h4cbd7ca63ce1aee9
   5:     0x55c042e5d192 - std::panicking::begin_panic::h93672d0313d5e8e9
   6:     0x55c042e5d100 - std::panicking::begin_panic_fmt::hd0daa02942245d81
   7:     0x55c042e5d081 - rust_begin_unwind
   8:     0x55c042e936df - core::panicking::panic_fmt::hbfc935564d134c1b
   9:     0x55c042e93683 - core::panicking::panic_bounds_check::h08d619adcd972898
  10:     0x55c042e1f3db - curl::easy::Easy::cvt::h8b0cee78a8555d56
  11:     0x55c042e1f1fd - curl::easy::Easy::setopt_path::h97000cc95ffaf29e
  12:     0x55c042e20e05 - curl::easy::default_configure::h81b9c3a40aadad76
  13:     0x55c042e1e715 - curl::easy::Easy::new::h6256decf6c19f143
  14:     0x55c042db16e4 - slack_hook::slack::Slack::send::h14b50e23bd1ee165
  15:     0x55c042dab5af - deployer::main::had2f8b13f079aa74
  16:     0x55c042e654e6 - __rust_maybe_catch_panic
  17:     0x55c042e5c3c2 - std::rt::lang_start::h53bf99b0829cc03c
  18:     0x7f176846682f - __libc_start_main
  19:     0x55c042da5e98 - _start
  20:                0x0 - <unknown>
  • 它编译并在macOS上工作(没有恐慌)。
  • 它在一个几乎全新的Ubuntu 16.04上编译但失败(见上面的错误)。

我的应用程序中有一些println!痕迹,所以我知道崩溃的位置,第20行的回溯似乎也说明了它。具有讽刺意味的是,该函数被称为success,并且是长脚本的最后一步:

fn success()  {
    let slack = Slack::new("https://hooks.slack.com/MY_HOOK_URL").unwrap();
    let p = PayloadBuilder::new()
        .text("Deployment success.")
        .channel("#app-notifier")
        .username("Deploy Bot")
        .icon_emoji(":tropical_drink:")
        .build()
        .unwrap();

    let res = slack.send(&p);
    match res {
        Ok(()) => println!("Success msg sent."),
        Err(x) => println!("<!> Success error ^^: {:?}",x)
    }
}

Slack URL在我的本地计算机上运行。如何自己解决这个特殊情况?我只需要一些线索。

1 个答案:

答案 0 :(得分:0)

这是卷曲生锈的问题。已在this issue中修复。我只需要运行cargo update,然后重建,现在一切正常。

感谢Lukas Kalbertodt,Alex Crichton以及他们帮助的生锈的作者。