diff --git a/buildpacks/dotnet/CHANGELOG.md b/buildpacks/dotnet/CHANGELOG.md index 8bf75fc..1ef92ca 100644 --- a/buildpacks/dotnet/CHANGELOG.md +++ b/buildpacks/dotnet/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Changed + +- Error messages are now printed to stderr. [#173](https://github.com/heroku/buildpacks-dotnet/pull/173) + ## [0.1.9] - 2024-12-04 ### Added diff --git a/buildpacks/dotnet/src/errors.rs b/buildpacks/dotnet/src/errors.rs index fbb644c..7bab544 100644 --- a/buildpacks/dotnet/src/errors.rs +++ b/buildpacks/dotnet/src/errors.rs @@ -5,7 +5,7 @@ use crate::layers::sdk::SdkLayerError; use crate::DotnetBuildpackError; use bullet_stream::{style, Print}; use indoc::formatdoc; -use std::io::{self, stdout}; +use std::io::{self, stderr}; pub(crate) fn on_error(error: libcnb::Error) { match error { @@ -308,7 +308,7 @@ fn log_io_error(header: &str, occurred_while: &str, io_error: &io::Error) { } fn log_error(header: impl AsRef, body: impl AsRef, error: Option) { - let mut log = Print::new(stdout()).without_header(); + let mut log = Print::new(stderr()).without_header(); if let Some(error) = error { let bullet = log.bullet(style::important("Debug info")); log = bullet.sub_bullet(error).done(); diff --git a/buildpacks/dotnet/tests/dotnet_publish_test.rs b/buildpacks/dotnet/tests/dotnet_publish_test.rs index 304b241..b17aec3 100644 --- a/buildpacks/dotnet/tests/dotnet_publish_test.rs +++ b/buildpacks/dotnet/tests/dotnet_publish_test.rs @@ -1,6 +1,6 @@ use crate::tests::default_build_config; -use indoc::formatdoc; -use libcnb_test::{assert_contains, assert_empty, TestRunner}; +use indoc::{formatdoc, indoc}; +use libcnb_test::{assert_contains, assert_empty, PackResult, TestRunner}; use regex::Regex; #[test] @@ -30,6 +30,33 @@ fn test_dotnet_publish_multi_tfm_solution() { ); } +#[test] +#[ignore = "integration test"] +fn test_dotnet_publish_with_compilation_error() { + TestRunner::default().build( + default_build_config("tests/fixtures/console_with_compilation_error") + .expected_pack_result(PackResult::Failure), + |context| { + assert_contains!( + &context.pack_stderr, + &indoc! {r" + ! Unable to publish + ! + ! The `dotnet publish` command exited unsuccessfully (exit status: 1). + ! + ! This error usually happens due to compilation errors. Use the command output + ! above to troubleshoot and retry your build. + ! + ! The publish process can also fail for a number of other reasons, such as + ! intermittent network issues, unavailability of the NuGet package feed and/or + ! other external dependencies, etc. + ! + ! Try again to see if the error resolves itself."} + ); + }, + ); +} + #[test] #[ignore = "integration test"] fn test_dotnet_publish_with_debug_configuration() { diff --git a/buildpacks/dotnet/tests/fixtures/console_with_compilation_error/Program.cs b/buildpacks/dotnet/tests/fixtures/console_with_compilation_error/Program.cs new file mode 100644 index 0000000..4b00b53 --- /dev/null +++ b/buildpacks/dotnet/tests/fixtures/console_with_compilation_error/Program.cs @@ -0,0 +1 @@ +Console.WriteFoo; diff --git a/buildpacks/dotnet/tests/fixtures/console_with_compilation_error/consoleapp.csproj b/buildpacks/dotnet/tests/fixtures/console_with_compilation_error/consoleapp.csproj new file mode 100644 index 0000000..2150e37 --- /dev/null +++ b/buildpacks/dotnet/tests/fixtures/console_with_compilation_error/consoleapp.csproj @@ -0,0 +1,10 @@ + + + + Exe + net8.0 + enable + enable + + +