# Receiving badarg converting list to reference on GitHub workflow and EUnit test

**URL:** <https://erlangforums.com/t/receiving-badarg-converting-list-to-reference-on-github-workflow-and-eunit-test/2619>\
**Category:** Questions / Help\
**Tags:** eunit, github\
**Created:** [May 21, 2023, 12:16am UTC](https://erlangforums.com/t/receiving-badarg-converting-list-to-reference-on-github-workflow-and-eunit-test/2619 "2023-05-21T00:16:35Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![williamthome](https://erlangforums.com/user_avatar/erlangforums.com/williamthome/32/471_2.png) [@williamthome](https://erlangforums.com/u/williamthome)\
**Post date:** [May 21, 2023, 12:16am UTC](https://erlangforums.com/t/receiving-badarg-converting-list-to-reference-on-github-workflow-and-eunit-test/2619/1 "2023-05-21T00:16:35Z")

</div>

Hey all.

I have a falling eunit test on GitHub, but locally all tests are ok.

The GitHub action log:

```erlang
Run rebar3 do eunit, ct
  
===> Verifying dependencies...
===> Analyzing applications...
===> Compiling changeset
===> Performing EUnit tests...
.............F..
Failures:

  1) changeset_reference_validator:validate_change_test/0: module 'changeset_reference_validator'
     Failure/Error: {error,badarg,
                        [{erlang,list_to_ref,
                             ["#Ref<0.4192537678.4073193475.71181>"],
                             [{error_info,#{module => erl_erts_errors}}]},
                         {changeset_reference_validator,validate_change_test,
                             0,
                             [{file,
                                  "/__w/changeset/changeset/src/validators/changeset_reference_validator.erl"},
                              {line,35}]},
                         {eunit_test,'-mf_wrapper/2-fun-0-',2,
                             [{file,"eunit_test.erl"},{line,273}]},
                         {eunit_test,run_testfun,1,
                             [{file,"eunit_test.erl"},{line,71}]},
                         {eunit_proc,run_test,1,
                             [{file,"eunit_proc.erl"},{line,531}]},
                         {eunit_proc,with_timeout,3,
                             [{file,"eunit_proc.erl"},{line,356}]},
                         {eunit_proc,handle_test,2,
                             [{file,"eunit_proc.erl"},{line,514}]},
                         {eunit_proc,tests_inorder,3,
                             [{file,"eunit_proc.erl"},{line,456}]}]}
     Output: 

Finished in 0.178 seconds
16 tests, 1 failures
===> Error running tests
Error: Process completed with exit code 1.

```

This is falling

```erlang
list_to_ref("#Ref<0.4192537678.4073193475.71181>").

```

but why?

This is my machine log:

```erlang
rebar3 do eunit, ct
===> Verifying dependencies...
===> Analyzing applications...
===> Compiling changeset
===> Performing EUnit tests...
................
Finished in 0.113 seconds
16 tests, 0 failures
===> Verifying dependencies...
===> Analyzing applications...
===> Compiling changeset
===> Running Common Test suites...
All 0 tests passed.

```

GitHub workflow and my machine are using the same `25.3.2` OTP version.

The lib repo: [GitHub - williamthome/changeset: An OTP library to validate data based on Ecto changeset library (Elixir).](https://github.com/williamthome/changeset)

I appreciate any help.

---

<div class="post-metadata">

**Author:** ![fancycade](https://erlangforums.com/user_avatar/erlangforums.com/fancycade/32/1187_2.png) [@fancycade](https://erlangforums.com/u/fancycade)\
**Post date:** [May 21, 2023, 1:42am UTC](https://erlangforums.com/t/receiving-badarg-converting-list-to-reference-on-github-workflow-and-eunit-test/2619/2 "2023-05-21T01:42:39Z")

</div>

Not much help but I reproduced your CI issue locally on my local machine (FreeBSD).

~~Maybe a missing dependency?~~

eunit failed, but everything else worked.

---

<div class="post-metadata">

**Author:** ![fancycade](https://erlangforums.com/user_avatar/erlangforums.com/fancycade/32/1187_2.png) [@fancycade](https://erlangforums.com/u/fancycade)\
**Post date:** [May 21, 2023, 2:09am UTC](https://erlangforums.com/t/receiving-badarg-converting-list-to-reference-on-github-workflow-and-eunit-test/2619/3 "2023-05-21T02:09:13Z")

</div>

Submitted a PR: [Fix list\_to\_ref string in unit test by fancycade · Pull Request #1 · williamthome/changeset · GitHub](https://github.com/williamthome/changeset/pull/1)

Passing build: [build #993137 - success](https://builds.sr.ht/~fancycade/job/993137)

---

<div class="post-metadata">

**Author:** ![williamthome](https://erlangforums.com/user_avatar/erlangforums.com/williamthome/32/471_2.png) [@williamthome](https://erlangforums.com/u/williamthome)\
**Post date:** [May 21, 2023, 7:24am UTC](https://erlangforums.com/t/receiving-badarg-converting-list-to-reference-on-github-workflow-and-eunit-test/2619/4 "2023-05-21T07:24:51Z")

</div>

Thanks, @fancycade!

`make_ref()` makes much more sense here.  
BTW, I got the reference value from the `list_to_ref` example in [Erlang docs](https://www.erlang.org/doc/man/erlang.html#list_to_ref-1):

```erlang
> list_to_ref("#Ref<0.4192537678.4073193475.71181>").
#Ref<0.4192537678.4073193475.71181>

```

Sounds strange to me why this happened. Any idea?

---

<div class="post-metadata">

**Author:** ![williamthome](https://erlangforums.com/user_avatar/erlangforums.com/williamthome/32/471_2.png) [@williamthome](https://erlangforums.com/u/williamthome)\
**Post date:** [May 21, 2023, 9:30am UTC](https://erlangforums.com/t/receiving-badarg-converting-list-to-reference-on-github-workflow-and-eunit-test/2619/5 "2023-05-21T09:30:35Z")

</div>

Oh, there is a big warning in the docs:

```erlang
This BIF is intended for debugging and is not to be used in application programs.

```

I will be considering this as the answer to my previous question.

---

<div class="post-metadata">

**Author:** ![fancycade](https://erlangforums.com/user_avatar/erlangforums.com/fancycade/32/1187_2.png) [@fancycade](https://erlangforums.com/u/fancycade)\
**Post date:** [May 21, 2023, 4:44pm UTC](https://erlangforums.com/t/receiving-badarg-converting-list-to-reference-on-github-workflow-and-eunit-test/2619/6 "2023-05-21T16:44:45Z")

</div>

I noticed that warning as well, but doesn’t explain why the Erlang docs ref doesn’t work.

```erlang
list_to_ref(ref_to_list(make_ref()))

```

As long as you use a different ref it works.

My guess was a breaking change with ref formats since the docs were published, but maybe there is a difference deeper down the stack. What OS are you running?

---

<div class="post-metadata">

**Author:** ![williamthome](https://erlangforums.com/user_avatar/erlangforums.com/williamthome/32/471_2.png) [@williamthome](https://erlangforums.com/u/williamthome)\
**Post date:** [May 21, 2023, 5:34pm UTC](https://erlangforums.com/t/receiving-badarg-converting-list-to-reference-on-github-workflow-and-eunit-test/2619/7 "2023-05-21T17:34:46Z")

</div>

> [@fancycade](#):
>
> What OS are you running?

```erlang
cat /etc/lsb-release 
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=22.04
DISTRIB_CODENAME=jammy
DISTRIB_DESCRIPTION="Ubuntu 22.04.2 LTS"

```

---

<div class="post-metadata">

**Author:** ![fancycade](https://erlangforums.com/user_avatar/erlangforums.com/fancycade/32/1187_2.png) [@fancycade](https://erlangforums.com/u/fancycade)\
**Post date:** [May 21, 2023, 9:16pm UTC](https://erlangforums.com/t/receiving-badarg-converting-list-to-reference-on-github-workflow-and-eunit-test/2619/8 "2023-05-21T21:16:56Z")

</div>

Hmmm i wouldnt expect that to cause issues. Maybe someone more experienced can solve the mystery.

---

<div class="post-metadata">

**Author:** ![gorillainduction](https://erlangforums.com/user_avatar/erlangforums.com/gorillainduction/32/1966_2.png) [@gorillainduction](https://erlangforums.com/u/gorillainduction)\
**Post date:** [May 23, 2023, 1:51pm UTC](https://erlangforums.com/t/receiving-badarg-converting-list-to-reference-on-github-workflow-and-eunit-test/2619/9 "2023-05-23T13:51:32Z")

</div>

> [@williamthome](#):
>
> ```erlang
> This BIF is intended for debugging and is not to be used in application programs.
> 
> ```
> 
> I will be considering this as the answer to my previous question.

\<tl;dr\> Yes, this is correct. Use this is for debugging and for logs exclusively. \</tl;dr\>

This is from memory, so it might not be totally correct, but rather an educated guess.

As I recall it, the first number in the reference is the node id (e.g., 0 for the local node), and then there is a scheduler id embedded in the reference so that you don’t have to aquire a lock when creating a reference in a scheduler. There are other things going on as well, but I think this is the culprit.

So, if you create a reference on a node with a lot of schedulers and you take the textual representation of the ref to another node with fewer schedulers, you might have created a ref that refers to a higher scheduler id than is avaliable on that node, but the 0 at the start tells the node that this should be treated as a ref that was created at the local node.

When sending refs that are not textual inbetween nodes, there will be a new node number in the ref on the remote node, and it will work anyway.

So, If I would hazard a guess, you were running the test on a decent development machine with a bunch of cores (and therefore a bunch of schedulers), and the ci system is running on fewer cores and hence fewer schedulers.

As an experiment and as anecdotal proof 😉

```erlang
1> list_to_ref("#Ref<0.4192537678.4073193475.71181>").
#Ref<0.4192537678.4073193475.71181>
2> erlang:system_info(schedulers).
3
```

and

```erlang
1> list_to_ref("#Ref<0.4192537678.4073193475.71181>").
** exception error: bad argument
     in function list_to_ref/1
        called as list_to_ref("#Ref<0.4192537678.4073193475.71181>")
        *** argument 1: not a textual representation of a reference
2> erlang:system_info(schedulers).
2
```

---

<div class="post-metadata">

**Author:** ![williamthome](https://erlangforums.com/user_avatar/erlangforums.com/williamthome/32/471_2.png) [@williamthome](https://erlangforums.com/u/williamthome)\
**Post date:** [May 24, 2023, 12:24am UTC](https://erlangforums.com/t/receiving-badarg-converting-list-to-reference-on-github-workflow-and-eunit-test/2619/10 "2023-05-24T00:24:14Z")

</div>

Interesting! I believe this is correct and will accept it as the solution.  
Glad to hear an experienced Erlanger.  
Thanks for the informative post, @gorillainduction!
