Skip to content

Commit

Permalink
Use #[derive(ErrorChain)] instead of error_chain!
Browse files Browse the repository at this point in the history
This cleans up the definition, and has slightly less finicky syntax.

Fixes #5
  • Loading branch information
fitzgen committed Sep 18, 2017
1 parent 9ffa24a commit 091dfcd
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 36 deletions.
11 changes: 11 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ path = "src/bin/starling.rs"
required-features = ["clap"]

[dependencies]
derive-error-chain = "0.11.0"
derive_is_enum_variant = "0.1.1"
error-chain = "0.11.0"
futures = "0.1.15"
Expand Down
71 changes: 36 additions & 35 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
#![allow(unused_doc_comment)]

#[macro_use]
extern crate derive_is_enum_variant;
extern crate derive_error_chain;
#[macro_use]
extern crate error_chain;
extern crate derive_is_enum_variant;
#[macro_use]
extern crate futures;
extern crate futures_cpupool;
Expand All @@ -22,7 +22,7 @@ extern crate tokio_core;

pub(crate) mod task;

use futures::{future, Future, Sink, Stream};
use futures::{Sink, Stream};
use futures_cpupool::CpuPool;
use futures::sync::mpsc;
use std::cmp;
Expand All @@ -33,38 +33,39 @@ use std::path;
use std::sync::Arc;
use std::thread;

error_chain! {
foreign_links {
Io(::std::io::Error)
/// An IO error.
;

SendError(mpsc::SendError<()>)
/// Tried to send a value on a channel when the receiving half was
/// already dropped.
;
}

errors {
/// Could not create a JavaScript runtime.
CouldNotCreateJavaScriptRuntime {
description("Could not create a JavaScript Runtime")
display("Could not create a JavaScript Runtime")
}

/// Could not read a value from a channel.
CouldNotReadValueFromChannel {
description("Could not read a value from a channel")
display("Could not read a value from a channel")
}

/// There was an exception in JavaScript code.
// TODO: stack, line, column, filename, etc
JavaScriptException {
description("JavaScript exception")
display("JavaScript exception")
}
}
/// The kind of error that occurred.
#[derive(Debug, ErrorChain)]
pub enum ErrorKind {
/// Some other kind of miscellaneous error, described in the given string.
Msg(String),

/// An IO error.
#[error_chain(foreign)]
Io(::std::io::Error),

/// Tried to send a value on a channel when the receiving half was already
/// dropped.
#[error_chain(foreign)]
SendError(mpsc::SendError<()>),

/// Could not create a JavaScript runtime.
#[error_chain(custom)]
#[error_chain(description = r#"|| "Could not create a JavaScript Runtime""#)]
#[error_chain(display = r#"|| write!(f, "Could not create a JavaScript Runtime")"#)]
CouldNotCreateJavaScriptRuntime,

/// Could not read a value from a channel.
#[error_chain(custom)]
#[error_chain(description = r#"|| "Could not read a value from a channel""#)]
#[error_chain(display = r#"|| write!(f, "Could not read a value from a channel")"#)]
CouldNotReadValueFromChannel,

/// There was an exception in JavaScript code.
// TODO: stack, line, column, filename, etc
#[error_chain(custom)]
#[error_chain(description = r#"|| "JavaScript exception""#)]
#[error_chain(display = r#"|| write!(f, "JavaScript exception")"#)]
JavaScriptException,
}

impl Clone for Error {
Expand Down
2 changes: 1 addition & 1 deletion src/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
//! [ongoing]: https://bugzilla.mozilla.org/show_bug.cgi?id=1323066
use super::{Error, ErrorKind, Result, StarlingHandle, StarlingMessage};
use futures::{self, future, Async, Future, Sink};
use futures::{self, Async, Future, Sink};
use futures::sync::oneshot;
use futures_cpupool::CpuFuture;
use futures::sync::mpsc;
Expand Down

0 comments on commit 091dfcd

Please sign in to comment.