Skip to content

bug: forge script crash when piping to command that doesn't take stdin: "failed printing to stdout: Broken pipe (os error 32)" #7055

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

Closed
2 tasks done
Tracked by #8794
burnto opened this issue Feb 8, 2024 · 2 comments
Assignees
Labels
C-forge Command: forge Cmd-forge-script Command: forge script T-bug Type: bug
Milestone

Comments

@burnto
Copy link

burnto commented Feb 8, 2024

Component

Forge

Have you ensured that all of these are up to date?

  • Foundry
  • Foundryup

What version of Foundry are you on?

forge 0.2.0 (a5efe4f 2024-02-08T00:16:00.244105000Z)

What command(s) is the bug in?

forge script

Operating System

macOS (Apple Silicon)

Describe the bug

In some cases, stdout pipe results in a panic when the process doesn't take stdin.

For example, here's my basic script:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;

import "forge-std/Script.sol";

contract Hello is Script {
    function run() public pure {
        console2.log("hello world");
    }
}

It runs fine directly, but when I attempt to pipe stdout to echo (which does not read stdin; I thought it did, but was incorrect), it crashes.

forge script script/Hello.s.sol  | echo

And here's the output:

The application panicked (crashed).
Message:  failed printing to stdout: Broken pipe (os error 32)
Location: library/std/src/io/stdio.rs:1021

This is a bug. Consider reporting it at https://github.com/foundry-rs/foundry

  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ BACKTRACE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
                                ⋮ 8 frames hidden ⋮                               
   9: std::io::stdio::_print::h4bb5fc4c58811fac
      at <unknown source file>:<unknown line>
  10: <foundry_compilers::report::BasicStdoutReporter as foundry_compilers::report::Reporter>::on_solc_spawn::ha378668ba63ad9f0
      at <unknown source file>:<unknown line>
  11: foundry_compilers::report::get_default_scoped::hf68384bfbe99a6b8
      at <unknown source file>:<unknown line>
  12: foundry_compilers::compile::project::FilteredCompilerSources::compile::h06281fe49e9f8591
      at <unknown source file>:<unknown line>
  13: foundry_compilers::compile::project::ProjectCompiler<T>::compile::hb5ec462c3b29078e
      at <unknown source file>:<unknown line>
  14: foundry_common::compile::ProjectCompiler::compile_with::{{closure}}::h1736f945e6d61a24
      at <unknown source file>:<unknown line>
  15: foundry_common::compile::ProjectCompiler::compile_with::h818227ff64524143
      at <unknown source file>:<unknown line>
  16: foundry_common::compile::compile_target_with_filter::hf657baba5344a969
      at <unknown source file>:<unknown line>
  17: forge::cmd::script::cmd::<impl forge::cmd::script::ScriptArgs>::run_script::{{closure}}::h920de20f26112464
      at <unknown source file>:<unknown line>
  18: foundry_cli::utils::block_on::hc78f4d5173423142
      at <unknown source file>:<unknown line>
  19: forge::main::hf3fcfb686887ccb3
      at <unknown source file>:<unknown line>
  20: std::sys_common::backtrace::__rust_begin_short_backtrace::h072fa4ebd6658625
      at <unknown source file>:<unknown line>
  21: std::rt::lang_start::h0ec9913e02b2517f
      at <unknown source file>:<unknown line>
  22: _main<unknown>
      at <unknown source file>:<unknown line>

Run with COLORBT_SHOW_HIDDEN=1 environment variable to disable frame filtering.
[1]    75117 abort      forge script script/Hello.s.sol

Thanks!

@burnto burnto added the T-bug Type: bug label Feb 8, 2024
@gakonst gakonst added this to Foundry Feb 8, 2024
@github-project-automation github-project-automation bot moved this to Todo in Foundry Feb 8, 2024
@burnto burnto changed the title forge script crash: "failed printing to stdout: Broken pipe (os error 32)" forge script crash when piping to command that doesn't take stdin: "failed printing to stdout: Broken pipe (os error 32)" Feb 8, 2024
@DaniPopes
Copy link
Member

We use the standard println! macros a lot, ideally this is an error and not a panic. Should be fixed after #6569

@zerosnacks zerosnacks added C-forge Command: forge Cmd-forge-script Command: forge script labels Jul 11, 2024
@zerosnacks zerosnacks changed the title forge script crash when piping to command that doesn't take stdin: "failed printing to stdout: Broken pipe (os error 32)" bug: forge script crash when piping to command that doesn't take stdin: "failed printing to stdout: Broken pipe (os error 32)" Jul 11, 2024
@zerosnacks zerosnacks added this to the v1.0.0 milestone Jul 26, 2024
@zerosnacks
Copy link
Member

Now yields:

Error: Broken pipe (os error 32)

instead of panicking w/ a backtrace

@github-project-automation github-project-automation bot moved this from Todo to Done in Foundry Nov 11, 2024
@grandizzy grandizzy moved this from Done to Completed in Foundry Nov 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-forge Command: forge Cmd-forge-script Command: forge script T-bug Type: bug
Projects
Status: Completed
Development

Successfully merging a pull request may close this issue.

3 participants