summaryrefslogtreecommitdiff
path: root/cli/installer.rs
diff options
context:
space:
mode:
Diffstat (limited to 'cli/installer.rs')
-rw-r--r--cli/installer.rs50
1 files changed, 21 insertions, 29 deletions
diff --git a/cli/installer.rs b/cli/installer.rs
index ac51d75f7..0f371e41a 100644
--- a/cli/installer.rs
+++ b/cli/installer.rs
@@ -2,15 +2,15 @@
use crate::flags::Flags;
use crate::global_state::GlobalState;
-use deno_core::ErrBox;
+use deno_core::error::generic_error;
+use deno_core::error::AnyError;
use deno_core::ModuleSpecifier;
use log::Level;
use regex::{Regex, RegexBuilder};
use std::env;
use std::fs;
use std::fs::File;
-use std::io::Error;
-use std::io::ErrorKind;
+use std::io;
use std::io::Write;
#[cfg(not(windows))]
use std::os::unix::fs::PermissionsExt;
@@ -32,14 +32,14 @@ pub fn is_remote_url(module_url: &str) -> bool {
lower.starts_with("http://") || lower.starts_with("https://")
}
-fn validate_name(exec_name: &str) -> Result<(), Error> {
+fn validate_name(exec_name: &str) -> Result<(), AnyError> {
if EXEC_NAME_RE.is_match(exec_name) {
Ok(())
} else {
- Err(Error::new(
- ErrorKind::Other,
- format!("Invalid executable name: {}", exec_name),
- ))
+ Err(generic_error(format!(
+ "Invalid executable name: {}",
+ exec_name
+ )))
}
}
@@ -50,7 +50,7 @@ fn validate_name(exec_name: &str) -> Result<(), Error> {
fn generate_executable_file(
file_path: PathBuf,
args: Vec<String>,
-) -> Result<(), Error> {
+) -> Result<(), AnyError> {
let args: Vec<String> = args.iter().map(|c| format!("\"{}\"", c)).collect();
let template = format!(
"% generated by deno install %\n@deno.exe {} %*\n",
@@ -65,7 +65,7 @@ fn generate_executable_file(
fn generate_executable_file(
file_path: PathBuf,
args: Vec<String>,
-) -> Result<(), Error> {
+) -> Result<(), AnyError> {
let args: Vec<String> = args.iter().map(|c| format!("\"{}\"", c)).collect();
let template = format!(
r#"#!/bin/sh
@@ -87,7 +87,7 @@ async fn generate_bundle(
flags: Flags,
module_specifier: ModuleSpecifier,
script_path: PathBuf,
-) -> Result<(), ErrBox> {
+) -> Result<(), AnyError> {
let global_state = GlobalState::new(flags.clone())?;
let source = global_state
.ts_compiler
@@ -98,7 +98,7 @@ async fn generate_bundle(
Ok(())
}
-fn get_installer_root() -> Result<PathBuf, Error> {
+fn get_installer_root() -> Result<PathBuf, io::Error> {
if let Ok(env_dir) = env::var("DENO_INSTALL_ROOT") {
if !env_dir.is_empty() {
return PathBuf::from(env_dir).canonicalize();
@@ -111,8 +111,8 @@ fn get_installer_root() -> Result<PathBuf, Error> {
env::var_os(home_env_var)
.map(PathBuf::from)
.ok_or_else(|| {
- Error::new(
- ErrorKind::NotFound,
+ io::Error::new(
+ io::ErrorKind::NotFound,
format!("${} is not defined", home_env_var),
)
})?;
@@ -142,7 +142,7 @@ pub async fn install(
name: Option<String>,
root: Option<PathBuf>,
force: bool,
-) -> Result<(), ErrBox> {
+) -> Result<(), AnyError> {
let root = if let Some(root) = root {
root.canonicalize()?
} else {
@@ -153,10 +153,7 @@ pub async fn install(
// ensure directory exists
if let Ok(metadata) = fs::metadata(&installation_dir) {
if !metadata.is_dir() {
- return Err(ErrBox::from(Error::new(
- ErrorKind::Other,
- "Installation path is not a directory",
- )));
+ return Err(generic_error("Installation path is not a directory"));
}
} else {
fs::create_dir_all(&installation_dir)?;
@@ -170,10 +167,9 @@ pub async fn install(
let name = match name {
Some(name) => name,
- None => return Err(ErrBox::from(Error::new(
- ErrorKind::Other,
+ None => return Err(generic_error(
"An executable name was not provided. One could not be inferred from the URL. Aborting.",
- ))),
+ )),
};
validate_name(name.as_str())?;
@@ -185,10 +181,9 @@ pub async fn install(
}
if file_path.exists() && !force {
- return Err(ErrBox::from(Error::new(
- ErrorKind::Other,
+ return Err(generic_error(
"Existing installation found. Aborting (Use -f to overwrite).",
- )));
+ ));
};
let mut executable_args = vec!["run".to_string()];
@@ -206,10 +201,7 @@ pub async fn install(
Level::Debug => "debug",
Level::Info => "info",
_ => {
- return Err(ErrBox::from(Error::new(
- ErrorKind::Other,
- format!("invalid log level {}", log_level),
- )))
+ return Err(generic_error(format!("invalid log level {}", log_level)))
}
};
executable_args.push(log_level.to_string());