# Better way to suppress error/backtrace on SIGPIPE in a pipeline?

**URL:** https://discourse.julialang.org/t/better-way-to-suppress-error-backtrace-on-sigpipe-in-a-pipeline/80801
**Category:** General Usage
**Created:** [May 10, 2022, 10:51am UTC](https://discourse.julialang.org/t/better-way-to-suppress-error-backtrace-on-sigpipe-in-a-pipeline/80801 "2022-05-10T10:51:26Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![martin.auer](https://avatars.discourse-cdn.com/v4/letter/m/f19dbf/32.png) [@martin.auer](https://discourse.julialang.org/u/martin.auer)
#### Post date: [May 10, 2022, 10:51am UTC](https://discourse.julialang.org/t/better-way-to-suppress-error-backtrace-on-sigpipe-in-a-pipeline/80801/1 "2022-05-10T10:51:26Z")

</div>

We are using custom scripts in a Linux/shell/pipeline environment shared by users with different language backgrounds. Julia would be a nice fit to some of the process stages.

As any such scripts might later be used and also read by people (yet) unfamiliar with Julia (but with, say, background in bash), I’d like to avoid anything that could be slightly frightening, and make a reader go “:q!”.

In our pipelines, we like to ignore SIGPIPE.

```julia
#!/usr/bin/env julia
function main()
    foreach(println, 1:1_000_000)
end
main()

```

```julia
bash> run.jl | head -n1
1
ERROR: LoadError: IOError: write: broken pipe (EPIPE)
Stacktrace:
  [1] uv_write(s::Base.PipeEndpoint, p::Ptr{UInt8}, n::UInt64)
    @ Base ./stream.jl:1010
...

```

To avoid this error/backtrace, we suppress an exception:

```julia
try
    main()
catch e
    isa(e, Base.IOError) && e.code == Base.UV_EPIPE && exit(0)
    rethrow()
end

```

(  
I found the code `UP_EPIPE` value used in julia/test/read.jl: [julia/read.jl at b4ab6eff13c3afe8188b7f7fa8b7589ea212ef24 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/blob/b4ab6eff13c3afe8188b7f7fa8b7589ea212ef24/test/read.jl)

There was also a 2015 thread [remove unwarranted handling of SIGPIPE instead of ignoring it. by amitmurthy · Pull Request #9956 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/pull/9956) and a mention of SIGPIPE / `sigdie_handler()` in JuliaDocumentation.pdf.  
)

My question would be if there is another, maybe more elegant/Julian way to ignore SIGPIPE?  
I found nothing equivalent to, say, `Base.exit_on_sigint()` / `atexit()`…  
Maybe playing with the default signal handlers could work? Any link on more background on those would be appreciated!
