From 4a6fc8e5420a8443bcbc7ebd1a6045013829ca57 Mon Sep 17 00:00:00 2001 From: Schneems Date: Thu, 31 Oct 2024 09:41:09 -0500 Subject: [PATCH 01/23] Replace output constant with bulletstream style --- buildpacks/ruby/src/user_errors.rs | 39 ++++++++++++++++-------------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/buildpacks/ruby/src/user_errors.rs b/buildpacks/ruby/src/user_errors.rs index d824ed2..3b923bb 100644 --- a/buildpacks/ruby/src/user_errors.rs +++ b/buildpacks/ruby/src/user_errors.rs @@ -1,22 +1,24 @@ use std::process::Command; +use crate::{DetectError, RubyBuildpackError}; +use bullet_stream::{state::Bullet, state::SubBullet, style, Print}; #[allow(clippy::wildcard_imports)] use commons::output::{ build_log::*, - fmt::{self, DEBUG_INFO}, + fmt::{self}, }; - -use crate::{DetectError, RubyBuildpackError}; use fun_run::{CmdError, CommandWithName}; use indoc::formatdoc; +const DEBUG_INFO_STR: &str = "Debug info"; pub(crate) fn on_error(err: libcnb::Error) { let log = BuildLog::new(std::io::stdout()).without_buildpack_name(); + let debug_info = style::important(DEBUG_INFO_STR); match cause(err) { Cause::OurError(error) => log_our_error(log, error), Cause::FrameworkError(error) => log - .section(DEBUG_INFO) + .section(&debug_info) .step(&error.to_string()) .announce() .error(&formatdoc! {" @@ -43,6 +45,7 @@ fn log_our_error(mut log: Box, error: RubyBuildpackError) { let ruby_versions_url = fmt::url("https://devcenter.heroku.com/articles/ruby-support#ruby-versions"); let rubygems_status_url = fmt::url("https://status.rubygems.org/"); + let debug_info = style::important(DEBUG_INFO_STR); match error { RubyBuildpackError::BuildpackDetectionError(DetectError::Gemfile(error)) => { @@ -113,7 +116,7 @@ fn log_our_error(mut log: Box, error: RubyBuildpackError) { if let Some(dir) = path.parent() { log = debug_cmd( log.section(&format!( - "{DEBUG_INFO} Contents of the {} directory", + "{debug_info} Contents of the {} directory", fmt::value(dir.to_string_lossy()) )), Command::new("ls").args(["la", &dir.to_string_lossy()]), @@ -136,7 +139,7 @@ fn log_our_error(mut log: Box, error: RubyBuildpackError) { // Future: // - In the future use a manifest file to list if version is available on a different stack // - In the future add a "did you mean" Levenshtein distance to see if they typoed like "3.6.0" when they meant "3.0.6" - log.section(DEBUG_INFO) + log.section(&debug_info) .step(&error.to_string()) .announce() .error(&formatdoc! {" @@ -151,11 +154,11 @@ fn log_our_error(mut log: Box, error: RubyBuildpackError) { } RubyBuildpackError::GemInstallBundlerCommandError(error) => { log = log - .section(DEBUG_INFO) + .section(&debug_info) .step(&error.to_string()) .end_section(); - log = debug_cmd(log.section(DEBUG_INFO), Command::new("gem").arg("env")); + log = debug_cmd(log.section(&debug_info), Command::new("gem").arg("env")); log.announce().error(&formatdoc! {" Error installing bundler @@ -174,7 +177,7 @@ fn log_our_error(mut log: Box, error: RubyBuildpackError) { // - Grep error output for common things like using sqlite3, use classic buildpack let local_command = local_command_debug(&error); log - .section(DEBUG_INFO) + .section(&debug_info) .step(&error.to_string()) .end_section() .announce() @@ -195,14 +198,14 @@ fn log_our_error(mut log: Box, error: RubyBuildpackError) { } RubyBuildpackError::BundleInstallDigestError(path, error) => { log = log - .section(DEBUG_INFO) + .section(&debug_info) .step(&error.to_string()) .end_section(); if let Some(dir) = path.parent() { log = debug_cmd( log.section(&format!( - "{DEBUG_INFO} Contents of the {} directory", + "{debug_info} Contents of the {} directory", fmt::value(dir.to_string_lossy()) )), Command::new("ls").args(["la", &dir.to_string_lossy()]), @@ -230,7 +233,7 @@ fn log_our_error(mut log: Box, error: RubyBuildpackError) { // - Annotate with information on requiring test or development only gems in the Rakefile let local_command = local_command_debug(&error); log = log - .section(DEBUG_INFO) + .section(&debug_info) .step(&error.to_string()) .end_section(); @@ -248,7 +251,7 @@ fn log_our_error(mut log: Box, error: RubyBuildpackError) { RubyBuildpackError::RakeAssetsPrecompileFailed(error) => { let local_command = local_command_debug(&error); log = log - .section(DEBUG_INFO) + .section(&debug_info) .step(&error.to_string()) .end_section(); @@ -267,7 +270,7 @@ fn log_our_error(mut log: Box, error: RubyBuildpackError) { // - Separate between failures in layer dirs or in app dirs, if we can isolate to an app dir we could debug more // to determine if there's bad permissions or bad file symlink log = log - .section(DEBUG_INFO) + .section(&debug_info) .step(&error.to_string()) .end_section(); @@ -283,13 +286,13 @@ fn log_our_error(mut log: Box, error: RubyBuildpackError) { } RubyBuildpackError::GemListGetError(error) => { log = log - .section(DEBUG_INFO) + .section(&debug_info) .step(&error.to_string()) .end_section(); - log = debug_cmd(log.section(DEBUG_INFO), Command::new("gem").arg("env")); + log = debug_cmd(log.section(&debug_info), Command::new("gem").arg("env")); - log = debug_cmd(log.section(DEBUG_INFO), Command::new("bundle").arg("env")); + log = debug_cmd(log.section(&debug_info), Command::new("bundle").arg("env")); log.announce().error(&formatdoc! {" Error detecting dependencies @@ -301,7 +304,7 @@ fn log_our_error(mut log: Box, error: RubyBuildpackError) { "}); } RubyBuildpackError::MetricsAgentError(error) => { - log.section(DEBUG_INFO) + log.section(&debug_info) .step(&error.to_string()) .end_section() .announce() From d945eb12718b07c796217f8c7ba6a06346c4cb4c Mon Sep 17 00:00:00 2001 From: Schneems Date: Thu, 31 Oct 2024 09:41:41 -0500 Subject: [PATCH 02/23] Replace output fmt functions with bulletstream style --- buildpacks/ruby/src/user_errors.rs | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/buildpacks/ruby/src/user_errors.rs b/buildpacks/ruby/src/user_errors.rs index 3b923bb..dd068a2 100644 --- a/buildpacks/ruby/src/user_errors.rs +++ b/buildpacks/ruby/src/user_errors.rs @@ -3,10 +3,7 @@ use std::process::Command; use crate::{DetectError, RubyBuildpackError}; use bullet_stream::{state::Bullet, state::SubBullet, style, Print}; #[allow(clippy::wildcard_imports)] -use commons::output::{ - build_log::*, - fmt::{self}, -}; +use commons::output::build_log::*; use fun_run::{CmdError, CommandWithName}; use indoc::formatdoc; const DEBUG_INFO_STR: &str = "Debug info"; @@ -41,10 +38,10 @@ pub(crate) fn on_error(err: libcnb::Error) { #[allow(clippy::too_many_lines)] fn log_our_error(mut log: Box, error: RubyBuildpackError) { let git_branch_url = - fmt::url("https://devcenter.heroku.com/articles/git#deploy-from-a-branch-besides-main"); + style::url("https://devcenter.heroku.com/articles/git#deploy-from-a-branch-besides-main"); let ruby_versions_url = - fmt::url("https://devcenter.heroku.com/articles/ruby-support#ruby-versions"); - let rubygems_status_url = fmt::url("https://status.rubygems.org/"); + style::url("https://devcenter.heroku.com/articles/ruby-support#ruby-versions"); + let rubygems_status_url = style::url("https://status.rubygems.org/"); let debug_info = style::important(DEBUG_INFO_STR); match error { @@ -108,7 +105,7 @@ fn log_our_error(mut log: Box, error: RubyBuildpackError) { log = log .section(&format!( "Could not find {}, details:", - fmt::value(path.to_string_lossy()) + style::value(path.to_string_lossy()) )) .step(&error.to_string()) .end_section(); @@ -117,7 +114,7 @@ fn log_our_error(mut log: Box, error: RubyBuildpackError) { log = debug_cmd( log.section(&format!( "{debug_info} Contents of the {} directory", - fmt::value(dir.to_string_lossy()) + style::value(dir.to_string_lossy()) )), Command::new("ls").args(["la", &dir.to_string_lossy()]), ); @@ -206,7 +203,7 @@ fn log_our_error(mut log: Box, error: RubyBuildpackError) { log = debug_cmd( log.section(&format!( "{debug_info} Contents of the {} directory", - fmt::value(dir.to_string_lossy()) + style::value(dir.to_string_lossy()) )), Command::new("ls").args(["la", &dir.to_string_lossy()]), ); @@ -332,7 +329,7 @@ fn cause(err: libcnb::Error) -> Cause { } fn local_command_debug(error: &CmdError) -> String { - let cmd_name = replace_app_path_with_relative(fmt::command(error.name())); + let cmd_name = replace_app_path_with_relative(style::command(error.name())); formatdoc! {" Ensure you can run the following command locally with no errors before attempting another build: @@ -351,7 +348,7 @@ fn replace_app_path_with_relative(contents: impl AsRef) -> String { fn debug_cmd(log: Box, command: &mut Command) -> Box { let mut stream = log.step_timed_stream(&format!( "Running debug command {}", - fmt::command(command.name()) + style::command(command.name()) )); match command.stream_output(stream.io(), stream.io()) { From 39b36cede2598dcf33f502116bbc7624577b38a7 Mon Sep 17 00:00:00 2001 From: Schneems Date: Thu, 31 Oct 2024 09:44:38 -0500 Subject: [PATCH 03/23] Replace output module with bullet_stream --- buildpacks/ruby/src/user_errors.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/buildpacks/ruby/src/user_errors.rs b/buildpacks/ruby/src/user_errors.rs index dd068a2..611fa6d 100644 --- a/buildpacks/ruby/src/user_errors.rs +++ b/buildpacks/ruby/src/user_errors.rs @@ -10,15 +10,15 @@ const DEBUG_INFO_STR: &str = "Debug info"; pub(crate) fn on_error(err: libcnb::Error) { let log = BuildLog::new(std::io::stdout()).without_buildpack_name(); + let output = Print::new(std::io::stdout()).without_header(); let debug_info = style::important(DEBUG_INFO_STR); match cause(err) { Cause::OurError(error) => log_our_error(log, error), Cause::FrameworkError(error) => - log - .section(&debug_info) - .step(&error.to_string()) - .announce() - .error(&formatdoc! {" + output + .bullet(&debug_info) + .sub_bullet(error.to_string()) + .error(formatdoc! {" Error: heroku/buildpack-ruby internal buildpack error The framework used by this buildpack encountered an unexpected error. From 92a61017e6fde685731430af234717b3894ad980 Mon Sep 17 00:00:00 2001 From: Schneems Date: Thu, 31 Oct 2024 09:45:22 -0500 Subject: [PATCH 04/23] Pass bullet_stream to error output --- buildpacks/ruby/src/user_errors.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/buildpacks/ruby/src/user_errors.rs b/buildpacks/ruby/src/user_errors.rs index 611fa6d..346f99c 100644 --- a/buildpacks/ruby/src/user_errors.rs +++ b/buildpacks/ruby/src/user_errors.rs @@ -1,3 +1,4 @@ +use std::io::Stdout; use std::process::Command; use crate::{DetectError, RubyBuildpackError}; @@ -13,7 +14,7 @@ pub(crate) fn on_error(err: libcnb::Error) { let output = Print::new(std::io::stdout()).without_header(); let debug_info = style::important(DEBUG_INFO_STR); match cause(err) { - Cause::OurError(error) => log_our_error(log, error), + Cause::OurError(error) => log_our_error(output, log, error), Cause::FrameworkError(error) => output .bullet(&debug_info) @@ -36,7 +37,11 @@ pub(crate) fn on_error(err: libcnb::Error) { } #[allow(clippy::too_many_lines)] -fn log_our_error(mut log: Box, error: RubyBuildpackError) { +fn log_our_error( + output: Print>, + mut log: Box, + error: RubyBuildpackError, +) { let git_branch_url = style::url("https://devcenter.heroku.com/articles/git#deploy-from-a-branch-besides-main"); let ruby_versions_url = From 0d5f96015d1e27ed293c201a598db7ceebe998c9 Mon Sep 17 00:00:00 2001 From: Schneems Date: Thu, 31 Oct 2024 09:46:23 -0500 Subject: [PATCH 05/23] Replace output with bullet_stream --- buildpacks/ruby/src/user_errors.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/buildpacks/ruby/src/user_errors.rs b/buildpacks/ruby/src/user_errors.rs index 346f99c..7cc9e43 100644 --- a/buildpacks/ruby/src/user_errors.rs +++ b/buildpacks/ruby/src/user_errors.rs @@ -51,7 +51,7 @@ fn log_our_error( match error { RubyBuildpackError::BuildpackDetectionError(DetectError::Gemfile(error)) => { - log.announce().error(&formatdoc! {" + output.error(formatdoc! {" Error: `Gemfile` found with error There was an error trying to read the contents of the application's Gemfile. \ @@ -63,7 +63,7 @@ fn log_our_error( "}); } RubyBuildpackError::BuildpackDetectionError(DetectError::PackageJson(error)) => { - log.announce().error(&formatdoc! {" + output.error(formatdoc! {" Error: `package.json` found with error The Ruby buildpack detected a package.json file but it is not readable \ @@ -79,7 +79,7 @@ fn log_our_error( "}); } RubyBuildpackError::BuildpackDetectionError(DetectError::GemfileLock(error)) => { - log.announce().error(&formatdoc! {" + output.error(formatdoc! {" Error: `Gemfile.lock` found with error There was an error trying to read the contents of the application's Gemfile.lock. \ @@ -91,7 +91,7 @@ fn log_our_error( "}); } RubyBuildpackError::BuildpackDetectionError(DetectError::YarnLock(error)) => { - log.announce().error(&formatdoc! {" + output.error(formatdoc! {" Error: `yarn.lock` found with error The Ruby buildpack detected a yarn.lock file but it is not readable \ From 1521a68a435ada0a0d5a2fdd3689c6a43809e813 Mon Sep 17 00:00:00 2001 From: Schneems Date: Thu, 31 Oct 2024 09:47:46 -0500 Subject: [PATCH 06/23] Replace output with bullet_stream --- buildpacks/ruby/src/user_errors.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/buildpacks/ruby/src/user_errors.rs b/buildpacks/ruby/src/user_errors.rs index 7cc9e43..7b96c84 100644 --- a/buildpacks/ruby/src/user_errors.rs +++ b/buildpacks/ruby/src/user_errors.rs @@ -38,7 +38,7 @@ pub(crate) fn on_error(err: libcnb::Error) { #[allow(clippy::too_many_lines)] fn log_our_error( - output: Print>, + mut output: Print>, mut log: Box, error: RubyBuildpackError, ) { @@ -107,13 +107,13 @@ fn log_our_error( "}); } RubyBuildpackError::MissingGemfileLock(path, error) => { - log = log - .section(&format!( + output = output + .bullet(format!( "Could not find {}, details:", style::value(path.to_string_lossy()) )) - .step(&error.to_string()) - .end_section(); + .sub_bullet(error.to_string()) + .done(); if let Some(dir) = path.parent() { log = debug_cmd( @@ -125,7 +125,7 @@ fn log_our_error( ); } - log.announce().error(&formatdoc! {" + output.error(formatdoc! {" Error: `Gemfile.lock` not found A `Gemfile.lock` file is required and was not found in the root of your application. From 5d3889bd9f2912365cf3df9a2a8a9f6863891702 Mon Sep 17 00:00:00 2001 From: Schneems Date: Thu, 31 Oct 2024 09:49:45 -0500 Subject: [PATCH 07/23] Replace output with bullet_stream --- buildpacks/ruby/src/user_errors.rs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/buildpacks/ruby/src/user_errors.rs b/buildpacks/ruby/src/user_errors.rs index 7b96c84..be5ff42 100644 --- a/buildpacks/ruby/src/user_errors.rs +++ b/buildpacks/ruby/src/user_errors.rs @@ -141,10 +141,9 @@ fn log_our_error( // Future: // - In the future use a manifest file to list if version is available on a different stack // - In the future add a "did you mean" Levenshtein distance to see if they typoed like "3.6.0" when they meant "3.0.6" - log.section(&debug_info) - .step(&error.to_string()) - .announce() - .error(&formatdoc! {" + output.bullet(debug_info) + .sub_bullet(error.to_string()) + .error(formatdoc! {" Error installing Ruby Could not install the detected Ruby version. Ensure that you're using a supported @@ -155,14 +154,14 @@ fn log_our_error( "}); } RubyBuildpackError::GemInstallBundlerCommandError(error) => { - log = log - .section(&debug_info) - .step(&error.to_string()) - .end_section(); + output = output + .bullet(&debug_info) + .sub_bullet(error.to_string()) + .done(); log = debug_cmd(log.section(&debug_info), Command::new("gem").arg("env")); - log.announce().error(&formatdoc! {" + output.error(formatdoc! {" Error installing bundler The ruby package managment tool, `bundler`, failed to install. Bundler is required From 915ef8cc07e96b6dec16ef0eba85ff030f580345 Mon Sep 17 00:00:00 2001 From: Schneems Date: Thu, 31 Oct 2024 14:01:30 -0500 Subject: [PATCH 08/23] Replace output with bullet_stream --- buildpacks/ruby/src/user_errors.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/buildpacks/ruby/src/user_errors.rs b/buildpacks/ruby/src/user_errors.rs index be5ff42..16c8a92 100644 --- a/buildpacks/ruby/src/user_errors.rs +++ b/buildpacks/ruby/src/user_errors.rs @@ -177,12 +177,11 @@ fn log_our_error( // Future: // - Grep error output for common things like using sqlite3, use classic buildpack let local_command = local_command_debug(&error); - log - .section(&debug_info) - .step(&error.to_string()) - .end_section() - .announce() - .error(&formatdoc! {" + output + .bullet(&debug_info) + .sub_bullet(error.to_string()) + .done() + .error(formatdoc! {" Error installing your applications's dependencies Could not install gems to the system via bundler. Gems are dependencies From f74fd78aad18f994da2e692021762f73a96ace44 Mon Sep 17 00:00:00 2001 From: Schneems Date: Thu, 31 Oct 2024 14:02:08 -0500 Subject: [PATCH 09/23] Replace output with bullet_stream --- buildpacks/ruby/src/user_errors.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/buildpacks/ruby/src/user_errors.rs b/buildpacks/ruby/src/user_errors.rs index 16c8a92..26dee18 100644 --- a/buildpacks/ruby/src/user_errors.rs +++ b/buildpacks/ruby/src/user_errors.rs @@ -197,10 +197,10 @@ fn log_our_error( "}); } RubyBuildpackError::BundleInstallDigestError(path, error) => { - log = log - .section(&debug_info) - .step(&error.to_string()) - .end_section(); + output = output + .bullet(&debug_info) + .sub_bullet(&error.to_string()) + .done(); if let Some(dir) = path.parent() { log = debug_cmd( @@ -212,7 +212,7 @@ fn log_our_error( ); } - log.announce().error(&formatdoc! {" + output.error(formatdoc! {" Error generating file digest An error occurred while generating a file digest. To provide the fastest possible From 0a8f4b3486b76e5fcc6244cc310174e61654447a Mon Sep 17 00:00:00 2001 From: Schneems Date: Thu, 31 Oct 2024 14:04:31 -0500 Subject: [PATCH 10/23] Replace output with bullet_stream --- buildpacks/ruby/src/user_errors.rs | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/buildpacks/ruby/src/user_errors.rs b/buildpacks/ruby/src/user_errors.rs index 26dee18..1b839b9 100644 --- a/buildpacks/ruby/src/user_errors.rs +++ b/buildpacks/ruby/src/user_errors.rs @@ -232,12 +232,11 @@ fn log_our_error( // Future: // - Annotate with information on requiring test or development only gems in the Rakefile let local_command = local_command_debug(&error); - log = log - .section(&debug_info) - .step(&error.to_string()) - .end_section(); - - log.announce().error(&formatdoc! {" + output + .bullet(debug_info) + .sub_bullet(error.to_string()) + .done() + .error(formatdoc! {" Error detecting rake tasks The Ruby buildpack uses rake task information from your application to guide @@ -250,12 +249,11 @@ fn log_our_error( } RubyBuildpackError::RakeAssetsPrecompileFailed(error) => { let local_command = local_command_debug(&error); - log = log - .section(&debug_info) - .step(&error.to_string()) - .end_section(); - - log.announce().error(&formatdoc! {" + output + .bullet(debug_info) + .sub_bullet(error.to_string()) + .done() + .error(formatdoc! {" Error compiling assets An error occured while compiling assets via rake command. From 0dbe22acc4a9016a5926aafbb52524915baed090 Mon Sep 17 00:00:00 2001 From: Schneems Date: Thu, 31 Oct 2024 14:06:33 -0500 Subject: [PATCH 11/23] Replace output with bullet_stream --- buildpacks/ruby/src/user_errors.rs | 31 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/buildpacks/ruby/src/user_errors.rs b/buildpacks/ruby/src/user_errors.rs index 1b839b9..1b69b94 100644 --- a/buildpacks/ruby/src/user_errors.rs +++ b/buildpacks/ruby/src/user_errors.rs @@ -267,12 +267,11 @@ fn log_our_error( // Future: // - Separate between failures in layer dirs or in app dirs, if we can isolate to an app dir we could debug more // to determine if there's bad permissions or bad file symlink - log = log - .section(&debug_info) - .step(&error.to_string()) - .end_section(); - - log.announce().error(&formatdoc! {" + output + .bullet(debug_info) + .sub_bullet(error.to_string()) + .done() + .error(formatdoc! {" Error caching frontend assets An error occurred while attempting to cache frontend assets, and the Ruby buildpack @@ -283,16 +282,16 @@ fn log_our_error( "}); } RubyBuildpackError::GemListGetError(error) => { - log = log - .section(&debug_info) - .step(&error.to_string()) - .end_section(); + output = output + .bullet(&debug_info) + .sub_bullet(error.to_string()) + .done(); log = debug_cmd(log.section(&debug_info), Command::new("gem").arg("env")); log = debug_cmd(log.section(&debug_info), Command::new("bundle").arg("env")); - log.announce().error(&formatdoc! {" + output.error(formatdoc! {" Error detecting dependencies The Ruby buildpack requires information about your application’s dependencies to @@ -302,11 +301,11 @@ fn log_our_error( "}); } RubyBuildpackError::MetricsAgentError(error) => { - log.section(&debug_info) - .step(&error.to_string()) - .end_section() - .announce() - .error(&formatdoc! {" + output + .bullet(debug_info) + .sub_bullet(error.to_string()) + .done() + .error(formatdoc! {" Error: Could not install Statsd agent An error occured while downloading and installing the metrics agent From 1d4c8d800e54a6d6bad8c73c6d2393c57209031f Mon Sep 17 00:00:00 2001 From: Schneems Date: Thu, 31 Oct 2024 14:11:22 -0500 Subject: [PATCH 12/23] Prepare to update debug command invocation --- buildpacks/ruby/src/user_errors.rs | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/buildpacks/ruby/src/user_errors.rs b/buildpacks/ruby/src/user_errors.rs index 1b69b94..821a3ae 100644 --- a/buildpacks/ruby/src/user_errors.rs +++ b/buildpacks/ruby/src/user_errors.rs @@ -116,7 +116,7 @@ fn log_our_error( .done(); if let Some(dir) = path.parent() { - log = debug_cmd( + log = debug_cmd_original( log.section(&format!( "{debug_info} Contents of the {} directory", style::value(dir.to_string_lossy()) @@ -159,7 +159,7 @@ fn log_our_error( .sub_bullet(error.to_string()) .done(); - log = debug_cmd(log.section(&debug_info), Command::new("gem").arg("env")); + log = debug_cmd_original(log.section(&debug_info), Command::new("gem").arg("env")); output.error(formatdoc! {" Error installing bundler @@ -203,7 +203,7 @@ fn log_our_error( .done(); if let Some(dir) = path.parent() { - log = debug_cmd( + log = debug_cmd_original( log.section(&format!( "{debug_info} Contents of the {} directory", style::value(dir.to_string_lossy()) @@ -287,9 +287,9 @@ fn log_our_error( .sub_bullet(error.to_string()) .done(); - log = debug_cmd(log.section(&debug_info), Command::new("gem").arg("env")); + log = debug_cmd_original(log.section(&debug_info), Command::new("gem").arg("env")); - log = debug_cmd(log.section(&debug_info), Command::new("bundle").arg("env")); + log = debug_cmd_original(log.section(&debug_info), Command::new("bundle").arg("env")); output.error(formatdoc! {" Error detecting dependencies @@ -345,7 +345,21 @@ fn replace_app_path_with_relative(contents: impl AsRef) -> String { app_path_re.replace_all(contents.as_ref(), "./").to_string() } -fn debug_cmd(log: Box, command: &mut Command) -> Box { +fn debug_cmd(mut log: Print>, command: &mut Command) -> Print> { + let result = log.stream_with( + format!("Running debug command {}", style::command(command.name())), + |stdout, stderr| command.stream_output(stdout, stderr), + ); + match result { + Ok(_) => log.done(), + Err(e) => log.sub_bullet(e.to_string()).done(), + } +} + +fn debug_cmd_original( + log: Box, + command: &mut Command, +) -> Box { let mut stream = log.step_timed_stream(&format!( "Running debug command {}", style::command(command.name()) From 5ab1e701d8c8c91671ebf8994044ba876db966a1 Mon Sep 17 00:00:00 2001 From: Schneems Date: Thu, 31 Oct 2024 14:13:20 -0500 Subject: [PATCH 13/23] Update debug_cmd calls to use bullet_stream --- buildpacks/ruby/src/user_errors.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/buildpacks/ruby/src/user_errors.rs b/buildpacks/ruby/src/user_errors.rs index 821a3ae..83c0b73 100644 --- a/buildpacks/ruby/src/user_errors.rs +++ b/buildpacks/ruby/src/user_errors.rs @@ -116,8 +116,8 @@ fn log_our_error( .done(); if let Some(dir) = path.parent() { - log = debug_cmd_original( - log.section(&format!( + output = debug_cmd( + output.bullet(format!( "{debug_info} Contents of the {} directory", style::value(dir.to_string_lossy()) )), @@ -159,7 +159,7 @@ fn log_our_error( .sub_bullet(error.to_string()) .done(); - log = debug_cmd_original(log.section(&debug_info), Command::new("gem").arg("env")); + output = debug_cmd(output.bullet(&debug_info), Command::new("gem").arg("env")); output.error(formatdoc! {" Error installing bundler @@ -203,8 +203,8 @@ fn log_our_error( .done(); if let Some(dir) = path.parent() { - log = debug_cmd_original( - log.section(&format!( + output = debug_cmd( + output.bullet(format!( "{debug_info} Contents of the {} directory", style::value(dir.to_string_lossy()) )), From b736704e3f436a890f519b94a759cb1842656bcb Mon Sep 17 00:00:00 2001 From: Schneems Date: Thu, 31 Oct 2024 14:14:53 -0500 Subject: [PATCH 14/23] Update debug_cmd calls to use bullet_stream --- buildpacks/ruby/src/user_errors.rs | 26 +++++--------------------- 1 file changed, 5 insertions(+), 21 deletions(-) diff --git a/buildpacks/ruby/src/user_errors.rs b/buildpacks/ruby/src/user_errors.rs index 83c0b73..01cf61a 100644 --- a/buildpacks/ruby/src/user_errors.rs +++ b/buildpacks/ruby/src/user_errors.rs @@ -287,9 +287,11 @@ fn log_our_error( .sub_bullet(error.to_string()) .done(); - log = debug_cmd_original(log.section(&debug_info), Command::new("gem").arg("env")); - - log = debug_cmd_original(log.section(&debug_info), Command::new("bundle").arg("env")); + output = debug_cmd(output.bullet(&debug_info), Command::new("gem").arg("env")); + output = debug_cmd( + output.bullet(&debug_info), + Command::new("bundle").arg("env"), + ); output.error(formatdoc! {" Error detecting dependencies @@ -356,24 +358,6 @@ fn debug_cmd(mut log: Print>, command: &mut Command) -> Print< } } -fn debug_cmd_original( - log: Box, - command: &mut Command, -) -> Box { - let mut stream = log.step_timed_stream(&format!( - "Running debug command {}", - style::command(command.name()) - )); - - match command.stream_output(stream.io(), stream.io()) { - Ok(_) => stream.finish_timed_stream().end_section(), - Err(e) => stream - .finish_timed_stream() - .step(&e.to_string()) - .end_section(), - } -} - #[cfg(test)] mod test { use super::*; From fa4f727832877150d5614f6885a79c10163db462 Mon Sep 17 00:00:00 2001 From: Schneems Date: Thu, 31 Oct 2024 14:15:19 -0500 Subject: [PATCH 15/23] Remove unused code --- buildpacks/ruby/src/user_errors.rs | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/buildpacks/ruby/src/user_errors.rs b/buildpacks/ruby/src/user_errors.rs index 01cf61a..9ee32cc 100644 --- a/buildpacks/ruby/src/user_errors.rs +++ b/buildpacks/ruby/src/user_errors.rs @@ -10,11 +10,10 @@ use indoc::formatdoc; const DEBUG_INFO_STR: &str = "Debug info"; pub(crate) fn on_error(err: libcnb::Error) { - let log = BuildLog::new(std::io::stdout()).without_buildpack_name(); let output = Print::new(std::io::stdout()).without_header(); let debug_info = style::important(DEBUG_INFO_STR); match cause(err) { - Cause::OurError(error) => log_our_error(output, log, error), + Cause::OurError(error) => log_our_error(output, error), Cause::FrameworkError(error) => output .bullet(&debug_info) @@ -37,11 +36,7 @@ pub(crate) fn on_error(err: libcnb::Error) { } #[allow(clippy::too_many_lines)] -fn log_our_error( - mut output: Print>, - mut log: Box, - error: RubyBuildpackError, -) { +fn log_our_error(mut output: Print>, error: RubyBuildpackError) { let git_branch_url = style::url("https://devcenter.heroku.com/articles/git#deploy-from-a-branch-besides-main"); let ruby_versions_url = From a6b8098e25d991ca641ae95db21469614027943e Mon Sep 17 00:00:00 2001 From: Schneems Date: Thu, 31 Oct 2024 14:15:37 -0500 Subject: [PATCH 16/23] Remove unused imports --- buildpacks/ruby/src/user_errors.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/buildpacks/ruby/src/user_errors.rs b/buildpacks/ruby/src/user_errors.rs index 9ee32cc..202d5ef 100644 --- a/buildpacks/ruby/src/user_errors.rs +++ b/buildpacks/ruby/src/user_errors.rs @@ -3,8 +3,6 @@ use std::process::Command; use crate::{DetectError, RubyBuildpackError}; use bullet_stream::{state::Bullet, state::SubBullet, style, Print}; -#[allow(clippy::wildcard_imports)] -use commons::output::build_log::*; use fun_run::{CmdError, CommandWithName}; use indoc::formatdoc; const DEBUG_INFO_STR: &str = "Debug info"; From cb2e6e0f21f186a6129064569713eed096753fd1 Mon Sep 17 00:00:00 2001 From: Schneems Date: Thu, 31 Oct 2024 14:42:19 -0500 Subject: [PATCH 17/23] Clippy --- buildpacks/ruby/src/user_errors.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buildpacks/ruby/src/user_errors.rs b/buildpacks/ruby/src/user_errors.rs index 202d5ef..92e13a4 100644 --- a/buildpacks/ruby/src/user_errors.rs +++ b/buildpacks/ruby/src/user_errors.rs @@ -192,7 +192,7 @@ fn log_our_error(mut output: Print>, error: RubyBuildpackError) { RubyBuildpackError::BundleInstallDigestError(path, error) => { output = output .bullet(&debug_info) - .sub_bullet(&error.to_string()) + .sub_bullet(error.to_string()) .done(); if let Some(dir) = path.parent() { From b36c6dafa4a4f293b1f313083611a4a5704e3c53 Mon Sep 17 00:00:00 2001 From: Schneems Date: Thu, 31 Oct 2024 14:42:37 -0500 Subject: [PATCH 18/23] Indentation --- buildpacks/ruby/src/user_errors.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/buildpacks/ruby/src/user_errors.rs b/buildpacks/ruby/src/user_errors.rs index 92e13a4..7d5f9bc 100644 --- a/buildpacks/ruby/src/user_errors.rs +++ b/buildpacks/ruby/src/user_errors.rs @@ -47,8 +47,8 @@ fn log_our_error(mut output: Print>, error: RubyBuildpackError) { output.error(formatdoc! {" Error: `Gemfile` found with error - There was an error trying to read the contents of the application's Gemfile. \ - The buildpack cannot continue if the Gemfile is unreadable. + There was an error trying to read the contents of the application's Gemfile. \ + The buildpack cannot continue if the Gemfile is unreadable. {error} From 093310f416b33031aead3c46c717055e87d206f0 Mon Sep 17 00:00:00 2001 From: Schneems Date: Thu, 31 Oct 2024 14:42:50 -0500 Subject: [PATCH 19/23] Indentation --- buildpacks/ruby/src/user_errors.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/buildpacks/ruby/src/user_errors.rs b/buildpacks/ruby/src/user_errors.rs index 7d5f9bc..103e6ac 100644 --- a/buildpacks/ruby/src/user_errors.rs +++ b/buildpacks/ruby/src/user_errors.rs @@ -230,15 +230,15 @@ fn log_our_error(mut output: Print>, error: RubyBuildpackError) { .sub_bullet(error.to_string()) .done() .error(formatdoc! {" - Error detecting rake tasks + Error detecting rake tasks - The Ruby buildpack uses rake task information from your application to guide - build logic. Without this information, the Ruby buildpack cannot continue. + The Ruby buildpack uses rake task information from your application to guide + build logic. Without this information, the Ruby buildpack cannot continue. - {local_command} + {local_command} - Use the information above to debug further. - "}); + Use the information above to debug further. + "}); } RubyBuildpackError::RakeAssetsPrecompileFailed(error) => { let local_command = local_command_debug(&error); From 69a6053b675952c67e2529ea0c83245ccc58839d Mon Sep 17 00:00:00 2001 From: Schneems Date: Thu, 31 Oct 2024 14:43:02 -0500 Subject: [PATCH 20/23] Indentation --- buildpacks/ruby/src/user_errors.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/buildpacks/ruby/src/user_errors.rs b/buildpacks/ruby/src/user_errors.rs index 103e6ac..f3d4a03 100644 --- a/buildpacks/ruby/src/user_errors.rs +++ b/buildpacks/ruby/src/user_errors.rs @@ -247,14 +247,14 @@ fn log_our_error(mut output: Print>, error: RubyBuildpackError) { .sub_bullet(error.to_string()) .done() .error(formatdoc! {" - Error compiling assets + Error compiling assets - An error occured while compiling assets via rake command. + An error occured while compiling assets via rake command. - {local_command} + {local_command} - Use the information above to debug further. - "}); + Use the information above to debug further. + "}); } RubyBuildpackError::InAppDirCacheError(error) => { // Future: From 222adaeffb69d48d187ff6f0a0d2ff5c4c034df5 Mon Sep 17 00:00:00 2001 From: Schneems Date: Thu, 31 Oct 2024 14:43:21 -0500 Subject: [PATCH 21/23] Indentation --- buildpacks/ruby/src/user_errors.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/buildpacks/ruby/src/user_errors.rs b/buildpacks/ruby/src/user_errors.rs index f3d4a03..55b3b16 100644 --- a/buildpacks/ruby/src/user_errors.rs +++ b/buildpacks/ruby/src/user_errors.rs @@ -265,14 +265,14 @@ fn log_our_error(mut output: Print>, error: RubyBuildpackError) { .sub_bullet(error.to_string()) .done() .error(formatdoc! {" - Error caching frontend assets + Error caching frontend assets - An error occurred while attempting to cache frontend assets, and the Ruby buildpack - cannot continue. + An error occurred while attempting to cache frontend assets, and the Ruby buildpack + cannot continue. - Ensure that the permissions on the files in your application directory are correct and that - all symlinks correctly resolve. - "}); + Ensure that the permissions on the files in your application directory are correct and that + all symlinks correctly resolve. + "}); } RubyBuildpackError::GemListGetError(error) => { output = output From c8bb95727b70b4d172370ebfe93a0a0f5b1207bb Mon Sep 17 00:00:00 2001 From: Schneems Date: Thu, 31 Oct 2024 14:43:26 -0500 Subject: [PATCH 22/23] Indentation --- buildpacks/ruby/src/user_errors.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buildpacks/ruby/src/user_errors.rs b/buildpacks/ruby/src/user_errors.rs index 55b3b16..7c665bd 100644 --- a/buildpacks/ruby/src/user_errors.rs +++ b/buildpacks/ruby/src/user_errors.rs @@ -305,7 +305,7 @@ fn log_our_error(mut output: Print>, error: RubyBuildpackError) { An error occured while downloading and installing the metrics agent the buildpack cannot continue. - "}); + "}); } } } From 0def92aa450ab100907acbda801942332649bdc8 Mon Sep 17 00:00:00 2001 From: Schneems Date: Sat, 2 Nov 2024 10:21:59 -0500 Subject: [PATCH 23/23] Update imports --- buildpacks/ruby/src/user_errors.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/buildpacks/ruby/src/user_errors.rs b/buildpacks/ruby/src/user_errors.rs index 7c665bd..3c781e7 100644 --- a/buildpacks/ruby/src/user_errors.rs +++ b/buildpacks/ruby/src/user_errors.rs @@ -1,10 +1,9 @@ -use std::io::Stdout; -use std::process::Command; - use crate::{DetectError, RubyBuildpackError}; use bullet_stream::{state::Bullet, state::SubBullet, style, Print}; use fun_run::{CmdError, CommandWithName}; use indoc::formatdoc; +use std::io::Stdout; +use std::process::Command; const DEBUG_INFO_STR: &str = "Debug info"; pub(crate) fn on_error(err: libcnb::Error) {