Bad run script for gleam

Piping gleam run output to grep drops the exit code.
I propose:

exec gleam run --module main -- "$@" | grep -v "Compiled in" | grep -v "Running main.main"
exit ${PIPESTATUS[0]}
1 Like

PIPESTATUS only works in bash… maybe use recently(4 days ago) merged no-print-progress flag

1 Like

Ok i got around it with this run script:

#!/bin/sh

# TODO: Use --no-print-progress once https://github.com/gleam-lang/gleam/issues/2299 is implemented
output=$(gleam run --module main -- "$@")
code=$?

echo "$output" | tail -n +3
exit $code
2 Likes

Ahhh - I knew something was going to break when I was working on that hack :sweat:

Will keep an eye on the gleam repo and wait for the next minor release…

1 Like

I couldn’t get either script to work for me (the PIPESTATUS solution exited with 2 and the tail solution was failing on stdout checks for me). I ended up adding the line

set -o pipefail

above my exec call in run.sh. So the full script looks like

#!/bin/sh
#
# This script is used to run your program on CodeCrafters
#
# This runs after .codecrafters/compile.sh
#
# Learn more: https://codecrafters.io/program-interface

set -e # Exit on failure
set -o pipefail # Prevent masking pipe failures

# TODO: Use --no-print-progress once https://github.com/gleam-lang/gleam/issues/2299 is implemented
exec gleam run --module lox -- "$@" | grep -v "Compiled in" | grep -v "Running lox.main"

1 Like

I’ve had to modify this again for #WZ8. The expectation is error code 65, but the test runner reported error code 1.

Locally, I was seeing error code 65 reported after running. I suspect the set -o pipefail didn’t work for some reason on the test runner? So it was exiting with 65, but then the two grep commands ran and returned status code 1 (because there was no other stdout output, like the equivalent of echo "a\nb" | grep -v "a" | grep -v "b", which, if you follow up with echo $?, will print 1).

My new run script is

#!/bin/sh
#
# This script is used to run your program on CodeCrafters
#
# This runs after .codecrafters/compile.sh
#
# Learn more: https://codecrafters.io/program-interface

set -e # Exit on failure
set -o pipefail # Prevent masking pipe failures

# TODO: Use --no-print-progress once https://github.com/gleam-lang/gleam/issues/2299 is implemented
exec gleam run --module lox -- "$@" | { grep -v "Compiled in" || true; } | { grep -v "Running lox.main" || true; }
2 Likes

@codebycaleb thanks for sharing this!

and just an update on this issue overall: Louis (Gleam maintainer) mentioned that the next release should be out this week or next, we’ll update as soon as that’s available!

2 Likes

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