Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace unimplemented macro with ErrorDetails variant #399

Merged
merged 1 commit into from
May 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions crates/notion-core/src/error/details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,11 @@ pub enum ErrorDetails {
/// Thrown when serializing the toolchain to JSON fails
StringifyToolchainError,

/// Thrown when a given feature has not yet been implemented
Unimplemented {
feature: String,
},

/// Thrown when unpacking an archive (tarball or zip) fails
UnpackArchiveError {
tool: String,
Expand Down Expand Up @@ -758,6 +763,7 @@ at {}
ErrorDetails::StringifyToolchainError => write!(f, "Could not serialize toolchain settings.

{}", REPORT_BUG_CTA),
ErrorDetails::Unimplemented { feature } => write!(f, "{} is not supported yet.", feature),
ErrorDetails::UnpackArchiveError { tool, version } => write!(f, "Could not unpack {} v{}

Please ensure the correct version is specified.", tool, version),
Expand Down Expand Up @@ -902,6 +908,7 @@ impl NotionFail for ErrorDetails {
ErrorDetails::StringifyPackageConfigError => ExitCode::UnknownError,
ErrorDetails::StringifyPlatformError => ExitCode::UnknownError,
ErrorDetails::StringifyToolchainError => ExitCode::UnknownError,
ErrorDetails::Unimplemented { .. } => ExitCode::UnknownError,
ErrorDetails::UnpackArchiveError { .. } => ExitCode::UnknownError,
ErrorDetails::UnrecognizedShell { .. } => ExitCode::EnvironmentError,
ErrorDetails::UnspecifiedPostscript => ExitCode::EnvironmentError,
Expand Down
1 change: 1 addition & 0 deletions crates/notion-core/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ impl EventLog {

pub fn publish(&mut self, plugin: Option<&Publish>) {
match plugin {
// Note: This call to unimplemented is left in, as it's not a Fallible operation that can use ErrorDetails::Unimplemented
Some(&Publish::Url(_)) => unimplemented!(),
Some(&Publish::Bin(ref command)) => {
let mut monitor = Monitor::new(command);
Expand Down
20 changes: 14 additions & 6 deletions crates/notion-core/src/tool/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::process::{Command, ExitStatus};
use lazy_static::lazy_static;
use regex::Regex;

use notion_fail::{Fallible, ResultExt};
use notion_fail::{throw, Fallible, ResultExt};
use validate_npm_package_name::{validate, Validity};

use crate::command::create_command;
Expand Down Expand Up @@ -69,21 +69,29 @@ impl ToolSpec {
match self {
ToolSpec::Node(version) => session.install_node(&version)?,
// ISSUE(#292): Implement install for npm
ToolSpec::Npm(_version) => unimplemented!("Installing npm is not supported yet"),
ToolSpec::Npm(_version) => throw!(ErrorDetails::Unimplemented {
feature: "Installing npm".into()
}),
ToolSpec::Yarn(version) => session.install_yarn(&version)?,
ToolSpec::Package(name, version) => {
session.install_package(name.to_string(), &version)?;
}
}
};
Ok(())
}

pub fn uninstall(&self, session: &mut Session) -> Fallible<()> {
match self {
ToolSpec::Node(_version) => unimplemented!("Uninstalling Node not supported yet"),
ToolSpec::Node(_version) => throw!(ErrorDetails::Unimplemented {
feature: "Uninstalling node".into()
}),
// ISSUE(#292): Implement install for npm
ToolSpec::Npm(_version) => unimplemented!("Uninstalling Npm not supported yet"),
ToolSpec::Yarn(_version) => unimplemented!("Uninstalling Yarn not supported yet"),
ToolSpec::Npm(_version) => throw!(ErrorDetails::Unimplemented {
feature: "Uninstalling npm".into()
}),
ToolSpec::Yarn(_version) => throw!(ErrorDetails::Unimplemented {
feature: "Uninstalling yarn".into()
}),
ToolSpec::Package(name, _version) => {
session.uninstall_package(name.to_string())?;
}
Expand Down
12 changes: 8 additions & 4 deletions src/command/activate.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use structopt::StructOpt;

use notion_core::error::ErrorDetails;
use notion_core::platform::System;
use notion_core::session::{ActivityKind, Session};
use notion_core::shell::{CurrentShell, Postscript, Shell};
Expand All @@ -15,10 +16,13 @@ impl Command for Activate {
session.add_event_start(ActivityKind::Activate);
let shell = CurrentShell::detect()?;

let postscript = match System::enabled_path()?.into_string() {
Ok(path) => Postscript::Activate(path),
Err(_) => unimplemented!(),
};
let path =
System::enabled_path()?
.into_string()
.map_err(|_| ErrorDetails::Unimplemented {
feature: "notion activate".into(),
})?;
let postscript = Postscript::Activate(path);

shell.save_postscript(&postscript)?;
session.add_event_end(ActivityKind::Activate, ExitCode::Success);
Expand Down
11 changes: 7 additions & 4 deletions src/command/deactivate.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use structopt::StructOpt;

use notion_core::error::ErrorDetails;
use notion_core::platform::System;
use notion_core::session::{ActivityKind, Session};
use notion_core::shell::{CurrentShell, Postscript, Shell};
Expand All @@ -15,10 +16,12 @@ impl Command for Deactivate {
session.add_event_start(ActivityKind::Deactivate);
let shell = CurrentShell::detect()?;

let postscript = match System::path()?.into_string() {
Ok(path) => Postscript::Deactivate(path),
Err(_) => unimplemented!(),
};
let path = System::path()?
.into_string()
.map_err(|_| ErrorDetails::Unimplemented {
feature: "notion deactivate".into(),
})?;
let postscript = Postscript::Deactivate(path);

shell.save_postscript(&postscript)?;
session.add_event_end(ActivityKind::Deactivate, ExitCode::Success);
Expand Down
7 changes: 5 additions & 2 deletions src/command/fetch.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use structopt::StructOpt;

use notion_core::error::ErrorDetails;
use notion_core::session::{ActivityKind, Session};
use notion_core::tool::ToolSpec;
use notion_fail::{ExitCode, Fallible};
use notion_fail::{throw, ExitCode, Fallible};

use crate::command::Command;

Expand Down Expand Up @@ -33,7 +34,9 @@ impl Command for Fetch {
}
ToolSpec::Npm(_version) => {
// ISSUE(#292): Implement install for npm
unimplemented!("Fetching npm is not supported yet");
throw!(ErrorDetails::Unimplemented {
feature: "Fetching npm".into()
});
}
ToolSpec::Package(name, version) => {
session.fetch_package(&name, &version)?;
Expand Down
4 changes: 3 additions & 1 deletion src/command/pin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ impl Command for Pin {
ToolSpec::Node(version) => session.pin_node(&version)?,
ToolSpec::Yarn(version) => session.pin_yarn(&version)?,
// ISSUE(#292): Implement install for npm
ToolSpec::Npm(_version) => unimplemented!("Pinning npm is not supported yet"),
ToolSpec::Npm(_version) => throw!(ErrorDetails::Unimplemented {
feature: "Pinning npm".into()
}),
ToolSpec::Package(name, _version) => {
throw!(ErrorDetails::CannotPinPackage { package: name })
}
Expand Down