Skip to content

Commit

Permalink
'printhandler' use starlark error instead of anyhow
Browse files Browse the repository at this point in the history
Summary: Don't think it's needed for anyhow->buck2_error migration, but could be useful to remove anyhow dependency on `buck2_interpreter` entirely

Reviewed By: JakobDegen

Differential Revision: D66377030

fbshipit-source-id: 3f975e20c9ff2e56a693721e11ee406376291148
  • Loading branch information
Will-MingLun-Li authored and facebook-github-bot committed Nov 25, 2024
1 parent ddb3467 commit decc502
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions starlark/src/stdlib/extra.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,13 @@ impl fmt::Display for PrintWrapper<'_, '_> {
/// Invoked from `print` or `pprint` to print a value.
pub trait PrintHandler {
/// If this function returns error, evaluation fails with this error.
fn println(&self, text: &str) -> anyhow::Result<()>;
fn println(&self, text: &str) -> crate::Result<()>;
}

pub(crate) struct StderrPrintHandler;

impl PrintHandler for StderrPrintHandler {
fn println(&self, text: &str) -> anyhow::Result<()> {
fn println(&self, text: &str) -> crate::Result<()> {
eprintln!("{}", text);
Ok(())
}
Expand All @@ -136,7 +136,7 @@ pub fn print(builder: &mut GlobalsBuilder) {
fn print(
#[starlark(args)] args: UnpackTuple<Value>,
eval: &mut Evaluator,
) -> anyhow::Result<NoneType> {
) -> starlark::Result<NoneType> {
// In practice most users should want to put the print somewhere else, but this does for now
// Unfortunately, we can't use PrintWrapper because strings to_str() and Display are different.
eval.print_handler
Expand All @@ -150,7 +150,7 @@ pub fn pprint(builder: &mut GlobalsBuilder) {
fn pprint(
#[starlark(args)] args: UnpackTuple<Value>,
eval: &mut Evaluator,
) -> anyhow::Result<NoneType> {
) -> starlark::Result<NoneType> {
// In practice most users may want to put the print somewhere else, but this does for now
eval.print_handler
.println(&format!("{:#}", PrintWrapper(&args.items)))?;
Expand Down Expand Up @@ -268,7 +268,7 @@ assert_eq(["11",8], map(double, ["1",4]))
s: Rc<RefCell<String>>,
}
impl PrintHandler for PrintHandlerImpl {
fn println(&self, s: &str) -> anyhow::Result<()> {
fn println(&self, s: &str) -> crate::Result<()> {
*self.s.borrow_mut() = s.to_owned();
Ok(())
}
Expand Down

0 comments on commit decc502

Please sign in to comment.