Skip to content

Commit

Permalink
[Stacked PR] Remove warn_later from output
Browse files Browse the repository at this point in the history
The `warn_later` functionality relies on global state in a way that we're not thrilled about putting into everyone's build packs by default. This removes the feature, plain and simple.
  • Loading branch information
schneems committed Jan 18, 2024
1 parent 87f4d6c commit 6521058
Show file tree
Hide file tree
Showing 5 changed files with 0 additions and 426 deletions.
72 changes: 0 additions & 72 deletions libherokubuildpack/src/output/build_log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,19 +242,6 @@ where
writeln_now(&mut self.io, style::important(s.trim()));
writeln_now(&mut self.io, "");
}

fn log_warn_later_shared(&mut self, s: &str) {
let mut formatted = style::warning(s.trim());
formatted.push('\n');

match crate::output::warn_later::try_push(formatted) {
Ok(()) => {}
Err(error) => {
eprintln!("[Buildpack Warning]: Cannot use the delayed warning feature due to error: {error}");
self.log_warning_shared(s);
}
};
}
}

impl<T, W> ErrorLogger for AnnounceBuildLog<T, W>
Expand Down Expand Up @@ -283,15 +270,6 @@ where
self
}

fn warn_later(
mut self: Box<Self>,
s: &str,
) -> Box<dyn AnnounceLogger<ReturnTo = Self::ReturnTo>> {
self.log_warn_later_shared(s);

self
}

fn important(
mut self: Box<Self>,
s: &str,
Expand Down Expand Up @@ -321,14 +299,6 @@ where
self
}

fn warn_later(
mut self: Box<Self>,
s: &str,
) -> Box<dyn AnnounceLogger<ReturnTo = Self::ReturnTo>> {
self.log_warn_later_shared(s);
self
}

fn important(
mut self: Box<Self>,
s: &str,
Expand Down Expand Up @@ -514,7 +484,6 @@ mod test {
use crate::command::CommandExt;
use crate::output::style::{self, strip_control_codes};
use crate::output::util::{strip_trailing_whitespace, ReadYourWrite};
use crate::output::warn_later::WarnGuard;
use indoc::formatdoc;
use libcnb_test::assert_contains;
use pretty_assertions::assert_eq;
Expand Down Expand Up @@ -656,47 +625,6 @@ mod test {
assert_eq!(expected, strip_control_codes(reader.read_lossy().unwrap()));
}

#[test]
fn warn_later_doesnt_output_newline() {
let writer = ReadYourWrite::writer(Vec::new());
let reader = writer.reader();

let warn_later = WarnGuard::new(writer.clone());
BuildLog::new(writer)
.buildpack_name("Walkin' on the Sun")
.section("So don't delay, act now, supplies are running out")
.step("Allow if you're still alive, six to eight years to arrive")
.step("And if you follow, there may be a tomorrow")
.announce()
.warn_later("And all that glitters is gold")
.warn_later("Only shooting stars break the mold")
.end_announce()
.step("But if the offer's shunned")
.step("You might as well be walking on the Sun")
.end_section()
.finish_logging();

drop(warn_later);

let expected = formatdoc! {"
# Walkin' on the Sun
- So don't delay, act now, supplies are running out
- Allow if you're still alive, six to eight years to arrive
- And if you follow, there may be a tomorrow
- But if the offer's shunned
- You might as well be walking on the Sun
- Done (finished in < 0.1s)
! And all that glitters is gold
! Only shooting stars break the mold
"};

assert_eq!(expected, strip_control_codes(reader.read_lossy().unwrap()));
}

#[test]
fn announce_and_exit_makes_no_whitespace() {
let writer = ReadYourWrite::writer(Vec::new());
Expand Down
1 change: 0 additions & 1 deletion libherokubuildpack/src/output/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ pub trait AnnounceLogger: ErrorLogger + Debug {
type ReturnTo;

fn warning(self: Box<Self>, s: &str) -> Box<dyn AnnounceLogger<ReturnTo = Self::ReturnTo>>;
fn warn_later(self: Box<Self>, s: &str) -> Box<dyn AnnounceLogger<ReturnTo = Self::ReturnTo>>;
fn important(self: Box<Self>, s: &str) -> Box<dyn AnnounceLogger<ReturnTo = Self::ReturnTo>>;

fn end_announce(self: Box<Self>) -> Self::ReturnTo;
Expand Down
1 change: 0 additions & 1 deletion libherokubuildpack/src/output/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ pub mod interface;
pub mod section_log;
pub mod style;
mod util;
pub mod warn_later;
5 changes: 0 additions & 5 deletions libherokubuildpack/src/output/section_log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,6 @@ pub fn log_warning(s: impl AsRef<str>) {
logger().announce().warning(s.as_ref());
}

/// Print an warning block to the output at a later time
pub fn log_warning_later(s: impl AsRef<str>) {
logger().announce().warn_later(s.as_ref());
}

/// Print an important block to the output
pub fn log_important(s: impl AsRef<str>) {
logger().announce().important(s.as_ref());
Expand Down
Loading

0 comments on commit 6521058

Please sign in to comment.