Skip to content
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
49 changes: 30 additions & 19 deletions crates/cli/src/bin/installer.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
// If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.

#![allow(clippy::result_large_err)]

use andromeda::{CliError, CliResult};
use clap::{Args, Parser as ClapParser, Subcommand};
use serde::Deserialize;
Expand Down Expand Up @@ -125,7 +127,8 @@ fn install_andromeda(args: InstallArgs) -> CliResult<()> {
// Create installation directory
if !install_dir.exists() {
print_info("Creating installation directory...");
fs::create_dir_all(&install_dir).map_err(CliError::Io)?;
fs::create_dir_all(&install_dir)
.map_err(|e| CliError::runtime_error_simple(format!("IO error: {}", e)))?;
}

// Check if already installed
Expand Down Expand Up @@ -173,7 +176,8 @@ fn install_andromeda(args: InstallArgs) -> CliResult<()> {

// Install binary
print_info("Installing binary...");
fs::write(&binary_path, binary_data).map_err(CliError::Io)?;
fs::write(&binary_path, binary_data)
.map_err(|e| CliError::runtime_error_simple(format!("IO error: {}", e)))?;

print_success(&format!(
"Andromeda installed to: {}",
Expand Down Expand Up @@ -227,12 +231,13 @@ fn get_latest_version(verbose: bool) -> CliResult<String> {
&format!("andromeda-installer/{}", env!("CARGO_PKG_VERSION")),
)
.call()
.map_err(|e| CliError::TestExecution(format!("Failed to fetch release info: {e}")))?;
.map_err(|e| {
CliError::runtime_error_simple(format!("Failed to fetch release info: {e}"))
})?;

let release: GitHubRelease = response
.body_mut()
.read_json()
.map_err(|e| CliError::TestExecution(format!("Failed to parse release info: {e}")))?;
let release: GitHubRelease = response.body_mut().read_json().map_err(|e| {
CliError::runtime_error_simple(format!("Failed to parse release info: {e}"))
})?;

Ok(release.tag_name)
}
Expand All @@ -249,7 +254,7 @@ fn detect_platform() -> CliResult<String> {
("macos", "x86_64") => "andromeda-macos-amd64",
("macos", "aarch64") => "andromeda-macos-arm64",
_ => {
return Err(CliError::Config(format!(
return Err(CliError::runtime_error_simple(format!(
"Unsupported platform: {os} {arch}"
)));
}
Expand All @@ -269,14 +274,14 @@ fn download_file(url: &str, verbose: bool) -> CliResult<Vec<u8>> {
&format!("andromeda-installer/{}", env!("CARGO_PKG_VERSION")),
)
.call()
.map_err(|e| CliError::TestExecution(format!("Failed to download file: {e}")))?;
.map_err(|e| CliError::runtime_error_simple(format!("Failed to download file: {e}")))?;

let mut bytes = Vec::new();
response
.body_mut()
.as_reader()
.read_to_end(&mut bytes)
.map_err(CliError::Io)?;
.map_err(|e| CliError::runtime_error_simple(format!("IO error: {}", e)))?;

if verbose {
print_info(&format!("Downloaded {} bytes", bytes.len()));
Expand Down Expand Up @@ -371,7 +376,8 @@ fn install_satellites(satellites: Vec<String>, args: InstallArgs) -> CliResult<(
// Create installation directory
if !install_dir.exists() {
print_info("Creating installation directory...");
fs::create_dir_all(&install_dir).map_err(CliError::Io)?;
fs::create_dir_all(&install_dir)
.map_err(|e| CliError::runtime_error_simple(format!("IO error: {}", e)))?;
}

// Parse satellite list
Expand All @@ -386,7 +392,10 @@ fn install_satellites(satellites: Vec<String>, args: InstallArgs) -> CliResult<(
sat,
AVAILABLE_SATELLITES.join("\n - ")
));
return Err(CliError::Config(format!("Unknown satellite: {}", sat)));
return Err(CliError::runtime_error_simple(format!(
"Unknown satellite: {}",
sat
)));
}
}
satellites
Expand Down Expand Up @@ -476,8 +485,8 @@ fn install_single_satellite(

// Check if already installed
if binary_path.exists() && !args.force {
return Err(CliError::Config(
"already installed (use --force to reinstall)".to_string(),
return Err(CliError::runtime_error_simple(
"already installed (use --force to reinstall)",
));
}

Expand All @@ -496,24 +505,26 @@ fn install_single_satellite(
let binary_data = download_file(&download_url, args.verbose)?;

// Install binary
fs::write(&binary_path, binary_data).map_err(CliError::Io)?;
fs::write(&binary_path, binary_data)
.map_err(|e| CliError::runtime_error_simple(format!("IO error: {}", e)))?;

// Make executable on Unix systems
#[cfg(unix)]
{
use std::os::unix::fs::PermissionsExt;
let mut perms = fs::metadata(&binary_path)
.map_err(CliError::Io)?
.map_err(|e| CliError::runtime_error_simple(format!("IO error: {}", e)))?
.permissions();
perms.set_mode(0o755);
fs::set_permissions(&binary_path, perms).map_err(CliError::Io)?;
fs::set_permissions(&binary_path, perms)
.map_err(|e| CliError::runtime_error_simple(format!("IO error: {}", e)))?;
}

// Verify installation
if let Ok(output) = Command::new(&binary_path).arg("--version").output()
&& !output.status.success()
{
return Err(CliError::Config("verification failed".to_string()));
return Err(CliError::runtime_error_simple("verification failed"));
}

Ok(())
Expand All @@ -531,7 +542,7 @@ fn detect_rust_target() -> CliResult<String> {
("macos", "x86_64") => "x86_64-apple-darwin",
("macos", "aarch64") => "aarch64-apple-darwin",
_ => {
return Err(CliError::Config(format!(
return Err(CliError::runtime_error_simple(format!(
"Unsupported platform: {} {}",
os, arch
)));
Expand Down
4 changes: 3 additions & 1 deletion crates/cli/src/bin/satellite_bundle.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
// If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.

#![allow(clippy::result_large_err)]

/// Andromeda Satellite - Bundle
///
/// A minimal executable focused solely on bundling and minifying JavaScript/TypeScript files.
Expand Down Expand Up @@ -29,7 +31,7 @@ fn main() -> CliResult<()> {
let cli = Cli::parse();

andromeda::bundle::bundle(cli.input.to_str().unwrap(), cli.output.to_str().unwrap())
.map_err(|e| CliError::TestExecution(format!("Bundle failed: {e}")))?;
.map_err(|e| CliError::runtime_error_simple(format!("Bundle failed: {e}")))?;

println!("✅ Successfully bundled and minified to {:?}", cli.output);

Expand Down
4 changes: 3 additions & 1 deletion crates/cli/src/bin/satellite_check.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
// If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.

#![allow(clippy::result_large_err)]

/// Andromeda Satellite - Check
///
/// A minimal executable focused solely on type-checking TypeScript files.
Expand All @@ -27,7 +29,7 @@ fn main() -> CliResult<()> {
let config = andromeda::config::ConfigManager::load_or_default(None);

andromeda::check::check_files_with_config(&cli.paths, Some(config))
.map_err(|e| CliError::TestExecution(format!("{e}")))?;
.map_err(|e| CliError::runtime_error_simple(format!("{e}")))?;

Ok(())
}
4 changes: 3 additions & 1 deletion crates/cli/src/bin/satellite_compile.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
// If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.

#![allow(clippy::result_large_err)]

/// Andromeda Satellite - Compile
///
/// A minimal executable focused solely on compiling JavaScript/TypeScript files into executables.
Expand Down Expand Up @@ -42,7 +44,7 @@ fn main() -> CliResult<()> {
cli.verbose,
cli.no_strict,
)
.map_err(|e| CliError::TestExecution(format!("Compilation failed: {e}")))?;
.map_err(|e| CliError::runtime_error_simple(format!("Compilation failed: {e}")))?;

let mut config_info = Vec::new();
if cli.verbose {
Expand Down
6 changes: 4 additions & 2 deletions crates/cli/src/bin/satellite_fmt.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
// If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.

#![allow(clippy::result_large_err)]

/// Andromeda Satellite - Format
///
/// A minimal executable focused solely on formatting JavaScript/TypeScript files.
Expand Down Expand Up @@ -29,7 +31,7 @@ fn main() -> CliResult<()> {

let files_to_format =
andromeda::helper::find_formattable_files_for_format(&cli.paths, &config.format)
.map_err(|e| CliError::TestExecution(format!("{e}")))?;
.map_err(|e| CliError::runtime_error_simple(format!("{e}")))?;

if files_to_format.is_empty() {
let warning = Style::new().yellow().bold().apply_to("⚠️");
Expand All @@ -49,7 +51,7 @@ fn main() -> CliResult<()> {

for path in &files_to_format {
match andromeda::format::format_file(path)
.map_err(|e| CliError::TestExecution(format!("{e}")))?
.map_err(|e| CliError::runtime_error_simple(format!("{e}")))?
{
andromeda::format::FormatResult::Changed => formatted_count += 1,
andromeda::format::FormatResult::AlreadyFormatted => already_formatted_count += 1,
Expand Down
6 changes: 4 additions & 2 deletions crates/cli/src/bin/satellite_lint.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
// If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.

#![allow(clippy::result_large_err)]

/// Andromeda Satellite - Lint
///
/// A minimal executable focused solely on linting JavaScript/TypeScript files.
Expand Down Expand Up @@ -28,7 +30,7 @@ fn main() -> CliResult<()> {

let files_to_lint =
andromeda::helper::find_formattable_files_for_lint(&cli.paths, &config.lint)
.map_err(|e| CliError::TestExecution(format!("{e}")))?;
.map_err(|e| CliError::runtime_error_simple(format!("{e}")))?;

if files_to_lint.is_empty() {
println!("No lintable files found.");
Expand All @@ -46,7 +48,7 @@ fn main() -> CliResult<()> {
}

if had_issues {
return Err(CliError::TestExecution(
return Err(CliError::runtime_error_simple(
"Linting completed with errors".to_string(),
));
}
Expand Down
4 changes: 3 additions & 1 deletion crates/cli/src/bin/satellite_run.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
// If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.

#![allow(clippy::result_large_err)]

/// Andromeda Satellite - Run
///
/// A minimal executable focused solely on running JavaScript/TypeScript files.
Expand Down Expand Up @@ -44,7 +46,7 @@ fn main() -> CliResult<()> {
.collect();

andromeda::run::run(cli.verbose, cli.no_strict, runtime_files)
.map_err(|e| CliError::TestExecution(format!("{e}")))?;
.map_err(|e| CliError::runtime_error_simple(format!("{e}")))?;

Ok(())
}
14 changes: 9 additions & 5 deletions crates/cli/src/bin/wpt.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::result_large_err)]

use andromeda::{CliError, CliResult};
use clap::{Args, Parser as ClapParser};
use std::num::NonZeroUsize;
Expand Down Expand Up @@ -76,7 +78,9 @@ fn run_wpt_tests(args: RunArgs) -> CliResult<()> {
// In CI mode, automatically use expectations
let use_expectations = args.use_expectations || args.ci_mode;

let current_dir = std::env::current_dir().map_err(CliError::Io)?;
let current_dir = std::env::current_dir().map_err(|e| {
CliError::runtime_error_simple(format!("Failed to get current directory: {e}"))
})?;
let in_tests_dir = current_dir.ends_with("tests");

let wpt_dir = if args.wpt_dir.is_absolute() {
Expand Down Expand Up @@ -248,12 +252,12 @@ fn run_wpt_tests(args: RunArgs) -> CliResult<()> {
}
}

let status = cmd
.status()
.map_err(|e| CliError::TestExecution(format!("Failed to run WPT test runner: {e}")))?;
let status = cmd.status().map_err(|e| {
CliError::runtime_error_simple(format!("Failed to run WPT test runner: {e}"))
})?;

if !status.success() {
return Err(CliError::TestExecution(format!(
return Err(CliError::runtime_error_simple(format!(
"WPT test runner failed with exit code: {}",
status.code().unwrap_or(1)
)));
Expand Down
18 changes: 7 additions & 11 deletions crates/cli/src/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.

use crate::config::AndromedaConfig;
use crate::error::{AndromedaError, Result};
use crate::error::{CliError, CliResult};
use crate::helper::find_formattable_files;
use console::Style;
use miette as oxc_miette;
Expand Down Expand Up @@ -268,9 +268,9 @@ impl std::error::Error for TypeCheckError {}
pub fn check_file_with_config(
path: &PathBuf,
config_override: Option<AndromedaConfig>,
) -> Result<Vec<TypeCheckError>> {
) -> CliResult<Vec<TypeCheckError>> {
let content =
fs::read_to_string(path).map_err(|e| AndromedaError::file_read_error(path.clone(), e))?;
fs::read_to_string(path).map_err(|e| CliError::file_read_error(path.clone(), e))?;

check_file_content_with_config(path, &content, config_override)
}
Expand All @@ -281,7 +281,7 @@ pub fn check_file_content_with_config(
path: &PathBuf,
content: &str,
_config_override: Option<AndromedaConfig>,
) -> Result<Vec<TypeCheckError>> {
) -> CliResult<Vec<TypeCheckError>> {
let allocator = Allocator::default();
let source_type = SourceType::from_path(path).unwrap_or_default();

Expand Down Expand Up @@ -592,7 +592,7 @@ fn extract_type_mismatch_info(error_message: &str) -> (Option<String>, Option<St
pub fn check_files_with_config(
paths: &[PathBuf],
config_override: Option<AndromedaConfig>,
) -> Result<()> {
) -> CliResult<()> {
let files_to_check: Vec<PathBuf> = if paths.is_empty() {
// If no paths provided, check all TypeScript files in current directory
find_formattable_files(&[PathBuf::from(".")])
Expand Down Expand Up @@ -666,12 +666,8 @@ pub fn check_files_with_config(
let error_count = Style::new().red().bold().apply_to(total_errors);
let file_count = Style::new().red().bold().apply_to(files_with_errors);
println!("{warning} {complete_msg}: Found {error_count} error(s) in {file_count} file(s)");
return Err(AndromedaError::runtime_error(
"Type checking completed with errors".to_string(),
None,
None,
None,
None,
return Err(CliError::runtime_error_simple(
"Type checking completed with errors",
));
}

Expand Down
Loading