# \[Go\] \[Builtin completion Stage #qp2\] Redirection test of stdout fails after implementing raw terminal mode

**URL:** <https://forum.codecrafters.io/t/go-builtin-completion-stage-qp2-redirection-test-of-stdout-fails-after-implementing-raw-terminal-mode/8012>\
**Category:** Challenges\
**Tags:** challenge:shell\
**Created:** [March 31, 2025, 10:09pm UTC](https://forum.codecrafters.io/t/go-builtin-completion-stage-qp2-redirection-test-of-stdout-fails-after-implementing-raw-terminal-mode/8012 "2025-03-31T22:09:56Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![TrulsElg](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/trulselg/32/4648_2.png) [@TrulsElg](https://forum.codecrafters.io/u/TrulsElg)\
**Post date:** [March 31, 2025, 10:09pm UTC](https://forum.codecrafters.io/t/go-builtin-completion-stage-qp2-redirection-test-of-stdout-fails-after-implementing-raw-terminal-mode/8012/1 "2025-03-31T22:09:56Z")

</div>

I’m stuck on Stage #qp2.  
I’m getting an error on a test that I don’t quite understand why the error occurs.

Primarily because I can’t reproduce the error locally. But also, the error message indicates that the stdout append redirect can’t open a file, which the append redirect should create if not already existing given that the enclosing directory exists.

Output from test:

```auto
remote: [tester::#UN3] Running tests for Stage #UN3 (Redirection - Append stderr)
remote: [tester::#UN3] [setup] export PATH=/tmp/banana/grape/banana:$PATH
remote: [tester::#UN3] Running ./your_program.sh
remote: [your-program] $ ls -1 nonexistent >> /tmp/quz/baz.md
remote: [tester::#UN3] Failed to read file ("/tmp/quz/baz.md"): open /tmp/quz/baz.md: no such file or directory
remote: [your-program]
remote: [tester::#UN3] Assertion failed.
remote: [tester::#UN3] Test failed (try setting 'debug: true' in your codecrafters.yml to see more details)

```

Output when testing my shell locally (as expected, stderr is not redirected, since this command redirects stdout):

```auto
./your_program.sh
$ ls -1 nonexistent >> /tmp/quz/baz.md
ls: nonexistent: No such file or directory
$ ls /tmp/quz/
baz.md
$ cat /tmp/quz/baz.md
$

```

I am primarily testing by git push, in case that information is relevant.

Code is available at Github: [GitHub - TrulsElg/codecrafters-shell-go at master](https://github.com/TrulsElg/codecrafters-shell-go/tree/master)

---

<div class="post-metadata">

**Author:** ![andy1li](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/andy1li/32/10_2.png) [@andy1li](https://forum.codecrafters.io/u/andy1li)\
**Post date:** [April 1, 2025, 4:15am UTC](https://forum.codecrafters.io/t/go-builtin-completion-stage-qp2-redirection-test-of-stdout-fails-after-implementing-raw-terminal-mode/8012/4 "2025-04-01T04:15:06Z")

</div>

Hey @TrulsElg, I tried running your code against the previous stages, but it’s actually no longer passing a previous stage **#CZ2 (Handle invalid commands)**.

 ![image](https://canada1.discourse-cdn.com/flex003/uploads/codecrafters/original/2X/0/057ca718afe854614a68ed0f86426e677397de8f.png)

**Suggestions** :

1. Use [our CLI](https://docs.codecrafters.io/cli/installation) to test against previous stages by running:

```auto
codecrafters test --previous

```

1. Focus on fixing the early stages first, as later stages depend on them.

**Hint** :

- You might need to handle both \r and \n when parsing input.

---

<div class="post-metadata">

**Author:** ![TrulsElg](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/trulselg/32/4648_2.png) [@TrulsElg](https://forum.codecrafters.io/u/TrulsElg)\
**Post date:** [April 2, 2025, 4:53pm UTC](https://forum.codecrafters.io/t/go-builtin-completion-stage-qp2-redirection-test-of-stdout-fails-after-implementing-raw-terminal-mode/8012/6 "2025-04-02T16:53:46Z")

</div>

Thanks for the feedback @andy1li  
I’m not sure if I’ve set up the codecrafters CLI wrong somehow but the test is failing to compile my code, which seems strange to me as the code does compile locally.  
The output states that there’s a missing entry for the term package, but it’s there in the file.

```auto
[compile] cmd/myshell/main.go:5:2: missing go.sum entry for module providing package golang.org/x/term; to add:
[compile] go mod download golang.org/x/term
[compile] Looks like your code failed to compile.
[compile] If you think this is a CodeCrafters error, please let us know at hello@codecrafters.io.

```

Setting debug: true in the yml file gives no additional output.

---

<div class="post-metadata">

**Author:** ![andy1li](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/andy1li/32/10_2.png) [@andy1li](https://forum.codecrafters.io/u/andy1li)\
**Post date:** [April 2, 2025, 5:49pm UTC](https://forum.codecrafters.io/t/go-builtin-completion-stage-qp2-redirection-test-of-stdout-fails-after-implementing-raw-terminal-mode/8012/7 "2025-04-02T17:49:03Z")

</div>

@TrulsElg Looks like the `go.sum` file might’ve been accidentally deleted.

You can regenerate it by running:

```auto
go mod tidy

```

Let me know if that works!

---

<div class="post-metadata">

**Author:** ![TrulsElg](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/trulselg/32/4648_2.png) [@TrulsElg](https://forum.codecrafters.io/u/TrulsElg)\
**Post date:** [April 3, 2025, 7:57am UTC](https://forum.codecrafters.io/t/go-builtin-completion-stage-qp2-redirection-test-of-stdout-fails-after-implementing-raw-terminal-mode/8012/8 "2025-04-03T07:57:10Z")

</div>

@andy1li Thanks but the go.sum file in the repo is the same as I have locally.  
Running go mod tidy doesn’t alter it.

```auto
golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc=
golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.29.0 h1:L6pJp37ocefwRRtYPKSWOWzOtWSxVajvz2ldH/xi3iU=
golang.org/x/term v0.29.0/go.mod h1:6bl4lRlvVuDgSf3179VpIxBF0o10JUpXWOnI7nErv7s=

```

---

<div class="post-metadata">

**Author:** ![andy1li](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/andy1li/32/10_2.png) [@andy1li](https://forum.codecrafters.io/u/andy1li)\
**Post date:** [April 3, 2025, 12:31pm UTC](https://forum.codecrafters.io/t/go-builtin-completion-stage-qp2-redirection-test-of-stdout-fails-after-implementing-raw-terminal-mode/8012/10 "2025-04-03T12:31:04Z")

</div>

@TrulsElg Just tested it on your repo, and it seems to be working now.

Could you try re-cloning the repo and giving it another go?

 ![image](https://canada1.discourse-cdn.com/flex003/uploads/codecrafters/original/2X/8/83a6b0b842f3074c3b79ea91df32d4dfbb807e38.png)

---

<div class="post-metadata">

**Author:** ![TrulsElg](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/trulselg/32/4648_2.png) [@TrulsElg](https://forum.codecrafters.io/u/TrulsElg)\
**Post date:** [April 14, 2025, 1:06pm UTC](https://forum.codecrafters.io/t/go-builtin-completion-stage-qp2-redirection-test-of-stdout-fails-after-implementing-raw-terminal-mode/8012/13 "2025-04-14T13:06:47Z")

</div>

Hi @andy1li  
Appreciate the followup and apologies for my inactivity lately.

I’ve re-cloned the repo and able to produce the same error now:

 ![image](https://canada1.discourse-cdn.com/flex003/uploads/codecrafters/original/2X/e/e2d9d811ad780d3bf48ab92fc5aa312af54496f2.png)

Local execution:

```auto
./your_program.sh
$ invalid_orange_command
invalid_orange_command: command not found

```

I’ll have a look at handling both \r and \n as you suggested and update the thread.

---

<div class="post-metadata">

**Author:** ![TrulsElg](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/trulselg/32/4648_2.png) [@TrulsElg](https://forum.codecrafters.io/u/TrulsElg)\
**Post date:** [April 16, 2025, 5:59pm UTC](https://forum.codecrafters.io/t/go-builtin-completion-stage-qp2-redirection-test-of-stdout-fails-after-implementing-raw-terminal-mode/8012/14 "2025-04-16T17:59:17Z")

</div>

@andy1li As you pointed out, handling both CR and LF needed to happen and I was only handling CR.  
Updating to handle both in the same switch case sorted out the failing test.  
Thanks a bunch for your support!

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex003/uploads/codecrafters/original/3X/7/0/700657133935c15703e22c7c8870394f6e6dc27d.svg) [@system](https://forum.codecrafters.io/u/system)\
**Post date:** [April 21, 2025, 6:00pm UTC](https://forum.codecrafters.io/t/go-builtin-completion-stage-qp2-redirection-test-of-stdout-fails-after-implementing-raw-terminal-mode/8012/15 "2025-04-21T18:00:06Z")

</div>

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.
