Shell Failing on #GP4 due to #OO8 'Expected prompt ("$ ") but received ""'

I’m stuck on Stage #GP4.

All the tests are passing until first stage #OO8, where the tester seems to not receive the "$ " input before the test fails. When I ran the shell locally it does show "$ " on start up.
It used to work before but is somehow failing now.

I’ve tried

  • refactoring how the program finds executables. From loading all programs on start up, to asynchronously (go func() { ...}()) to not at all (the current version). But none of them worked.
  • refactoring how early it prints the "$ " line, e.g.
  • looking for similar errors, where I found reports on May 19 and Jun 14.
  • manually changing the language pack from 1.22 to 1.24 in codecrafters.yml but it told me to create a new repo instead.

It suggests this isn’t an uncommon issue. Is there some way for us to upgrade the language pack ourselves?

Here are my logs:

[compile] Compilation successful.
[tester::#IP1] Running tests for Stage #IP1 (Run a program)
[tester::#IP1] [setup] export PATH=/tmp/quz:$PATH
[tester::#IP1] [setup] Available executables:
[tester::#IP1] [setup] - custom_exe_1900
[tester::#IP1] [setup] - custom_exe_4685
[tester::#IP1] Running ./your_shell.sh
[your-program] $ custom_exe_1900 Alice Alice
[your-program] Program was passed 3 args (including program name).
[your-program] Arg #0 (program name): custom_exe_1900
[your-program] Arg #1: Alice
[your-program] Arg #2: Alice
[your-program] Program Signature: 1031512840
[tester::#IP1] ✓ Received expected response
[your-program] $ custom_exe_4685 Alice David David
[your-program] Program was passed 4 args (including program name).
[your-program] Arg #0 (program name): custom_exe_4685
[your-program] Arg #1: Alice
[your-program] Arg #2: David
[your-program] Arg #3: David
[your-program] Program Signature: 6637881288
[tester::#IP1] ✓ Received expected response
[your-program] $ 
[tester::#IP1] Test passed.
[tester::#MG5] Running tests for Stage #MG5 (The type builtin: executable files)
[tester::#MG5] [setup] export PATH=/tmp/qux:$PATH
[tester::#MG5] [setup] export PATH=/tmp/foo:$PATH
[tester::#MG5] [setup] PATH is now: /tmp/foo:/tmp/qux:/go/bin:...
[tester::#MG5] [setup] Available executables:
[tester::#MG5] [setup] - my_exe
[tester::#MG5] Running ./your_shell.sh
[your-program] $ type cat
[your-program] cat is /bin/cat
[tester::#MG5] ✓ Received expected response
[your-program] $ type cp
[your-program] cp is /bin/cp
[tester::#MG5] ✓ Received expected response
[your-program] $ type mkdir
[your-program] mkdir is /bin/mkdir
[tester::#MG5] ✓ Received expected response
[your-program] $ type my_exe
[your-program] my_exe is /tmp/foo/my_exe
[tester::#MG5] ✓ Received expected response
[your-program] $ type invalid_blueberry_command
[your-program] invalid_blueberry_command not found
[tester::#MG5] ✓ Received expected response
[your-program] $ type invalid_banana_command
[your-program] invalid_banana_command not found
[tester::#MG5] ✓ Received expected response
[your-program] $ 
[tester::#MG5] Test passed.
[tester::#EZ5] Running tests for Stage #EZ5 (The type builtin: builtins)
[tester::#EZ5] Running ./your_shell.sh
[your-program] $ type echo
[your-program] echo is a shell builtin
[tester::#EZ5] ✓ Received expected response
[your-program] $ type exit
[your-program] exit is a shell builtin
[tester::#EZ5] ✓ Received expected response
[your-program] $ type type
[your-program] type is a shell builtin
[tester::#EZ5] ✓ Received expected response
[your-program] $ type invalid_apple_command
[your-program] invalid_apple_command not found
[tester::#EZ5] ✓ Received expected response
[your-program] $ type invalid_pear_command
[your-program] invalid_pear_command not found
[tester::#EZ5] ✓ Received expected response
[your-program] $ 
[tester::#EZ5] Test passed.
[tester::#IZ3] Running tests for Stage #IZ3 (The echo builtin)
[tester::#IZ3] Running ./your_shell.sh
[your-program] $ echo blueberry grape mango
[your-program] blueberry grape mango
[tester::#IZ3] ✓ Received expected response
[your-program] $ echo pear mango
[your-program] pear mango
[tester::#IZ3] ✓ Received expected response
[your-program] $ 
[tester::#IZ3] Test passed.
[tester::#PN5] Running tests for Stage #PN5 (The exit builtin)
[tester::#PN5] Running ./your_shell.sh
[your-program] $ invalid_blueberry_command
[your-program] invalid_blueberry_command: command not found
[tester::#PN5] ✓ Received command not found message
[your-program] $ exit 0
[tester::#PN5] ✓ Program exited successfully
[tester::#PN5] ✓ No output after exit command
[tester::#PN5] Test passed.
[tester::#FF0] Running tests for Stage #FF0 (REPL)
[tester::#FF0] Running ./your_shell.sh
[your-program] $ invalid_command_1
[your-program] invalid_command_1: command not found
[tester::#FF0] ✓ Received command not found message
[your-program] $ invalid_command_2
[your-program] invalid_command_2: command not found
[tester::#FF0] ✓ Received command not found message
[your-program] $ invalid_command_3
[your-program] invalid_command_3: command not found
[tester::#FF0] ✓ Received command not found message
[your-program] $ invalid_command_4
[your-program] invalid_command_4: command not found
[tester::#FF0] ✓ Received command not found message
[your-program] $ invalid_command_5
[your-program] invalid_command_5: command not found
[tester::#FF0] ✓ Received command not found message
[your-program] $ 
[tester::#FF0] Test passed.
[tester::#CZ2] Running tests for Stage #CZ2 (Handle invalid commands)
[tester::#CZ2] Running ./your_shell.sh
[your-program] $ invalid_pineapple_command
[your-program] invalid_pineapple_command: command not found
[tester::#CZ2] ✓ Received command not found message
[tester::#CZ2] Test passed.
[tester::#OO8] Running tests for Stage #OO8 (Print a prompt)
[tester::#OO8] Running ./your_shell.sh
[tester::#OO8] Expected prompt ("$ ") but received ""
[tester::#OO8] Assertion failed.
[tester::#OO8] Test failed (try setting 'debug: true' in your codecrafters.yml to see more details)

And here’s a snippet of my code:

func main() {
	reader := bufio.NewReader(os.Stdin)
	for {
		fmt.Print("$ ")
		input, err := reader.ReadString('\n')
		if err != nil {
			fmt.Println("got error reading input:", err.Error())
			continue
		}
		err = runInput(input)
		if err != nil {
			fmt.Println(err.Error())
		}
	}
}

My current progress on github:
https://github.com/LyndonFan/codecrafters-shell-go

Hey @LyndonFan, I’ve upgraded the buildpack for your repo to v1.24 and pushed a new commit to it. You can run git pull to sync the changes.

Is there some way for us to upgrade the language pack ourselves?

The easiest way is to start a new repo. For existing repos, upgrades currently need to be done manually by our team.

1 Like

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