Fork of daniellemaywood.uk/gleam — Wasm codegen work
2

Configure Feed

Select the types of activity you want to include in your feed.

Print stderr when command fails

+63 -23
+5 -5
compiler-cli/src/beam_compiler.rs
··· 1 1 use gleam_core::{ 2 - error::Error, 2 + error::{Error, ShellCommandFailureReason}, 3 3 io::{FileSystemWriter, Stdio}, 4 4 paths, Result, 5 5 }; ··· 62 62 63 63 writeln!(inner.stdin, "{}.", args).map_err(|e| Error::ShellCommand { 64 64 program: "escript".into(), 65 - err: Some(e.kind()), 65 + reason: ShellCommandFailureReason::IoError(e.kind()), 66 66 })?; 67 67 68 68 let mut buf = String::new(); ··· 76 76 "gleam-compile-result-error" => { 77 77 return Err(Error::ShellCommand { 78 78 program: "escript".into(), 79 - err: None, 79 + reason: ShellCommandFailureReason::Unknown, 80 80 }) 81 81 } 82 82 s if s.starts_with("gleam-compile-module:") => { ··· 96 96 // if we get here, stdout got closed before we got an "ok" or "err". 97 97 Err(Error::ShellCommand { 98 98 program: "escript".into(), 99 - err: None, 99 + reason: ShellCommandFailureReason::Unknown, 100 100 }) 101 101 } 102 102 ··· 126 126 }, 127 127 other => Error::ShellCommand { 128 128 program: "escript".into(), 129 - err: Some(other), 129 + reason: ShellCommandFailureReason::IoError(other), 130 130 }, 131 131 })?; 132 132
+7 -3
compiler-cli/src/dependencies.rs
··· 12 12 build::{Mode, Target, Telemetry}, 13 13 config::PackageConfig, 14 14 dependency, 15 - error::{FileIoAction, FileKind, StandardIoAction}, 15 + error::{FileIoAction, FileKind, ShellCommandFailureReason, StandardIoAction}, 16 16 hex::{self, HEXPM_PUBLIC_KEY}, 17 17 io::{HttpClient as _, TarUnpacker, WrappedReader}, 18 18 manifest::{Base16Checksum, Manifest, ManifestPackage, ManifestPackageSource}, ··· 904 904 fn execute_command(command: &mut Command) -> Result<std::process::Output> { 905 905 let output = command.output().map_err(|error| Error::ShellCommand { 906 906 program: "git".into(), 907 - err: Some(error.kind()), 907 + reason: ShellCommandFailureReason::IoError(error.kind()), 908 908 })?; 909 909 if output.status.success() { 910 910 Ok(output) 911 911 } else { 912 + let reason = match String::from_utf8(output.stderr) { 913 + Ok(stderr) => ShellCommandFailureReason::ShellCommandError(stderr), 914 + Err(_) => ShellCommandFailureReason::Unknown, 915 + }; 912 916 Err(Error::ShellCommand { 913 917 program: "git".into(), 914 - err: None, 918 + reason, 915 919 }) 916 920 } 917 921 }
+3 -3
compiler-cli/src/fs.rs
··· 1 1 use gleam_core::{ 2 2 build::{NullTelemetry, Target}, 3 - error::{parse_os, Error, FileIoAction, FileKind, OS}, 3 + error::{parse_os, Error, FileIoAction, FileKind, ShellCommandFailureReason, OS}, 4 4 io::{ 5 5 BeamCompiler, CommandExecutor, Content, DirEntry, FileSystemReader, FileSystemWriter, 6 6 OutputFile, ReadDir, Stdio, WrappedReader, ··· 214 214 215 215 other => Error::ShellCommand { 216 216 program: program.to_string(), 217 - err: Some(other), 217 + reason: ShellCommandFailureReason::IoError(other), 218 218 }, 219 219 }), 220 220 } ··· 661 661 662 662 other => Err(Error::ShellCommand { 663 663 program: "git".into(), 664 - err: Some(other), 664 + reason: ShellCommandFailureReason::IoError(other), 665 665 }), 666 666 }, 667 667 }
+2 -2
compiler-cli/src/shell.rs
··· 1 1 use gleam_core::{ 2 2 analyse::TargetSupport, 3 3 build::{Codegen, Compile, Mode, Options, Target}, 4 - error::Error, 4 + error::{Error, ShellCommandFailureReason}, 5 5 paths::ProjectPaths, 6 6 }; 7 7 use std::process::Command; ··· 43 43 tracing::info!("Running OS process {:?}", command); 44 44 let _ = command.status().map_err(|e| Error::ShellCommand { 45 45 program: "erl".into(), 46 - err: Some(e.kind()), 46 + reason: ShellCommandFailureReason::IoError(e.kind()), 47 47 })?; 48 48 Ok(()) 49 49 }
+2 -1
compiler-core/src/build/elixir_libraries.rs
··· 1 1 use crate::{ 2 + error::ShellCommandFailureReason, 2 3 io::{CommandExecutor, FileSystemReader, FileSystemWriter, Stdio}, 3 4 Error, 4 5 }; ··· 97 98 if status != 0 { 98 99 return Err(Error::ShellCommand { 99 100 program: "elixir".into(), 100 - err: None, 101 + reason: ShellCommandFailureReason::Unknown, 101 102 }); 102 103 } 103 104 }
+8 -5
compiler-core/src/build/project_compiler.rs
··· 1 1 use crate::{ 2 2 analyse::TargetSupport, 3 3 build::{ 4 - package_compiler, package_compiler::PackageCompiler, package_loader::StaleTracker, 5 - project_compiler, telemetry::Telemetry, Mode, Module, Origin, Package, Target, 4 + package_compiler::{self, PackageCompiler}, 5 + package_loader::StaleTracker, 6 + project_compiler, 7 + telemetry::Telemetry, 8 + Mode, Module, Origin, Package, Target, 6 9 }, 7 10 codegen::{self, ErlangApp}, 8 11 config::PackageConfig, 9 12 dep_tree, 10 - error::{FileIoAction, FileKind}, 13 + error::{FileIoAction, FileKind, ShellCommandFailureReason}, 11 14 io::{BeamCompiler, CommandExecutor, FileSystemReader, FileSystemWriter, Stdio}, 12 15 manifest::{ManifestPackage, ManifestPackageSource}, 13 16 metadata, ··· 385 388 } else { 386 389 Err(Error::ShellCommand { 387 390 program: "rebar3".into(), 388 - err: None, 391 + reason: ShellCommandFailureReason::Unknown, 389 392 }) 390 393 } 391 394 } ··· 483 486 } else { 484 487 Err(Error::ShellCommand { 485 488 program: "mix".into(), 486 - err: None, 489 + reason: ShellCommandFailureReason::Unknown, 487 490 }) 488 491 } 489 492 }
+36 -4
compiler-core/src/error.rs
··· 158 158 #[error("shell program `{program}` failed")] 159 159 ShellCommand { 160 160 program: String, 161 - err: Option<std::io::ErrorKind>, 161 + reason: ShellCommandFailureReason, 162 162 }, 163 163 164 164 #[error("{name} is not a valid project name")] ··· 375 375 "debian" => Distro::Debian, 376 376 _ => Distro::Other, 377 377 } 378 + } 379 + 380 + #[derive(Debug, Eq, PartialEq, Clone)] 381 + pub enum ShellCommandFailureReason { 382 + /// When we don't have any context about the failure 383 + Unknown, 384 + /// When the actual running of the command failed for some reason. 385 + IoError(std::io::ErrorKind), 386 + /// When the shell command returned an error status 387 + ShellCommandError(String), 378 388 } 379 389 380 390 impl Error { ··· 1164 1174 1165 1175 Error::ShellCommand { 1166 1176 program: command, 1167 - err: None, 1168 - } => { 1177 + reason: ShellCommandFailureReason::Unknown, 1178 + } => { 1169 1179 let text = 1170 1180 format!("There was a problem when running the shell command `{command}`."); 1171 1181 vec![Diagnostic { ··· 1179 1189 1180 1190 Error::ShellCommand { 1181 1191 program: command, 1182 - err: Some(err), 1192 + reason: ShellCommandFailureReason::IoError(err), 1183 1193 } => { 1184 1194 let text = format!( 1185 1195 "There was a problem when running the shell command `{}`. ··· 1189 1199 {}", 1190 1200 command, 1191 1201 std_io_error_kind_text(err) 1202 + ); 1203 + vec![Diagnostic { 1204 + title: "Shell command failure".into(), 1205 + text, 1206 + hint: None, 1207 + level: Level::Error, 1208 + location: None, 1209 + }] 1210 + } 1211 + 1212 + Error::ShellCommand { 1213 + program: command, 1214 + reason: ShellCommandFailureReason::ShellCommandError(err), 1215 + } => { 1216 + let text = format!( 1217 + "There was a problem when running the shell command `{}`. 1218 + 1219 + The error from the shell command was: 1220 + 1221 + {}", 1222 + command, 1223 + err 1192 1224 ); 1193 1225 vec![Diagnostic { 1194 1226 title: "Shell command failure".into(),