News for hackers. Stuff that matters.
Re:Overview of Rust error handling libraries by mikedilger on Friday November 22, 2019 @04:01PM (#21610034)
I like file and line numbers with my errors:

  // No need to use this directly. See the e!() macro.
  #[derive(Debug)]
  pub struct ErrInfo {
      pub file: &'static str,
      pub line: u32,
      pub msg: &'static str  
  }

  impl std::fmt::Display for ErrInfo {
      fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
          if cfg!(debug_assertions) {
              write!(f, "[{}:{}] {}", self.file, self.line, self.msg)
          } else {
              write!(f, "{}", self.msg)
          }
      }
  }

  /// Use this with `failure` crate's `ResultExt` like this
  ///
  /// ```
  ///    $r = function().context(e!("Function failed"))?;
  /// ```
  ///
  /// Error context will then include that message, and the file and line number.
  #[macro_export]
  macro_rules! e {
      ($msg:expr) => {
          $crate::ErrInfo {
              file: file!(),
              line: line!(),
              msg: $msg
          }
      };
  }
Re:Overview of Rust error handling libraries by epage on Friday November 22, 2019 @05:09PM (#21610653)
Some of the highlighted error crates will include a full backtrace if you are using nightly rust. Not sure when it will hit stable.
Re:Overview of Rust error handling libraries by shepmaster on Friday November 22, 2019 @09:02PM (#21611928)
Some also produce backtraces on today's stable Rust and previous versions as well. SNAFU can produce backtraces back to stable Rust 1.31.
Re:Overview of Rust error handling libraries by Gibbon1 on Friday November 22, 2019 @06:54PM (#21611343)
I've been doing that sort of thing in firmware for a long time. Record the file, line number and the caller and restart. 90% of the time it's obvious what the problem is by inspection.