Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print errors to stderr #173

Merged
merged 4 commits into from
Dec 13, 2024
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
4 changes: 4 additions & 0 deletions buildpacks/dotnet/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions buildpacks/dotnet/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<DotnetBuildpackError>) {
match error {
Expand Down Expand Up @@ -308,7 +308,7 @@ fn log_io_error(header: &str, occurred_while: &str, io_error: &io::Error) {
}

fn log_error(header: impl AsRef<str>, body: impl AsRef<str>, error: Option<String>) {
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();
Expand Down
31 changes: 29 additions & 2 deletions buildpacks/dotnet/tests/dotnet_publish_test.rs
Original file line number Diff line number Diff line change
@@ -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]
Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Console.WriteFoo;
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>