Gleam: two-fer fails locally, passes on site

My two-fer solution is straightforward:

import gleam/option.{type Option}

pub fn two_fer(name: Option(String)) -> String {
  let id = option.unwrap(name, "you")
  "One for " <> id <> ", one for me."
}

It passes the test-runner.

Testing locally fails with a very cryptic message:

$ gleam test
   Compiled in 0.07s
    Running two_fer_test.main
exception error: #{function => <<"read_module">>,line => 74,
                   message => <<"Assertion pattern match failed">>,
                   module => <<"exercism/test_runner">>,
                   value => {error,not_utf8},
                   gleam_error => let_assert}
  in function  exercism@test_runner:read_module/1 (/home/parallels/src/exercism/exercism.io/gleam/two-fer/build/dev/erlang/exercism_test_runner/_gleam_artefacts/exercism@test_runner.erl, line 96)
  in call from gleam@list:do_map/3 (/home/parallels/src/exercism/exercism.io/gleam/two-fer/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@list.erl, line 119)
  in call from exercism@test_runner:main/0 (/home/parallels/src/exercism/exercism.io/gleam/two-fer/build/dev/erlang/exercism_test_runner/_gleam_artefacts/exercism@test_runner.erl, line 134)

I haven’t seen this with any of the other 20 or so exercises I’ve done.

This appears to be an error from simplifile propagating up, but there’s nothing spooky about my source file

$ file src/two_fer.gleam 
src/two_fer.gleam: ASCII text

$ od -c src/two_fer.gleam 
0000000   i   m   p   o   r   t       g   l   e   a   m   /   o   p   t
0000020   i   o   n   .   {   t   y   p   e       O   p   t   i   o   n
0000040   }  \n  \n   p   u   b       f   n       t   w   o   _   f   e
0000060   r   (   n   a   m   e   :       O   p   t   i   o   n   (   S
0000100   t   r   i   n   g   )   )       -   >       S   t   r   i   n
0000120   g       {  \n           l   e   t       i   d       =       o
0000140   p   t   i   o   n   .   u   n   w   r   a   p   (   n   a   m
0000160   e   ,       o   r   :       "   y   o   u   "   )  \n        
0000200   "   O   n   e       f   o   r       "       <   >       i   d
0000220       <   >       "   ,       o   n   e       f   o   r       m
0000240   e   .   "  \n   }  \n
0000246

What version of Gleam are you using?

Root cause identified: the test runner package is trying to load a hidden vim swap file as a gleam module.

Working it out in exercism/gleam-test-runner#63

4 Likes

Great debugging! :slight_smile: