gleam-lang / gleam

⭐️ A friendly language for building type-safe, scalable systems!
https://gleam.run
Apache License 2.0
17.58k stars 733 forks source link

Empty file src/application.gleam crashes process #2006

Closed rradczewski closed 1 year ago

rradczewski commented 1 year ago

Creating an empty file named src/application.gleam will cause a crash as follows:

$ docker run --rm ghcr.io/gleam-lang/gleam:v0.26.2-erlang bash -c 'gleam new someproject; touch someproject/src/application.gleam; cd someproject; gleam test'
Your Gleam project someproject has been successfully created.
The project can be compiled and tested by running these commands:

    cd someproject
    gleam test

  Resolving versions
Downloading packages
 Downloaded 2 packages in 0.05s
  Compiling gleam_stdlib
  Compiling gleeunit
  Compiling someproject
   Compiled in 0.64s
    Running someproject_test.main
{"init terminating in do_boot",{undef,[{application,load,[{application,stdlib,[{description,"ERTS  CXC 138 10"},{vsn,"4.2"},{id,[]},{modules,[array,base64,beam_lib,binary,c,calendar,dets,dets_server,dets_sup,dets_utils,dets_v9,dict,digraph,digraph_utils,edlin,edlin_expand,epp,eval_bits,erl_abstract_code,erl_anno,erl_bits,erl_compile,erl_error,erl_eval,erl_expand_records,erl_features,erl_internal,erl_lint,erl_parse,erl_posix_msg,erl_pp,erl_scan,erl_stdlib_errors,erl_tar,error_logger_file_h,error_logger_tty_h,escript,ets,file_sorter,filelib,filename,gb_trees,gb_sets,gen,gen_event,gen_fsm,gen_server,gen_statem,io,io_lib,io_lib_format,io_lib_fread,io_lib_pretty,lists,log_mf_h,maps,math,ms_transform,orddict,ordsets,otp_internal,peer,pool,proc_lib,proplists,qlc,qlc_pt,queue,rand,random,re,sets,shell,shell_default,shell_docs,slave,sofs,string,supervisor,supervisor_bridge,sys,timer,unicode,unicode_util,uri_string,win32reg,zip]},{registered,[timer_server,rsh_starter,take_over_monitor,pool_master,dets]},{applications,[kernel]},{optional_applications,[]},{included_applications,[]},{env,[]},{maxT,infinity},{maxP,infinity}]}],[]},{init,eval_script,2,[]},{init,do_boot,3,[]}]}}
init terminating in do_boot ({undef,[{application,load,[{_}],[]},{init,eval_script,2,[]},{init,do_boot,3,[]}]})

Crash dump is being written to: erl_crash.dump...done

I stumbled upon this by accident while creating a kata-bootstrap for gleam, and I kept getting crashes when running gleam new application; cd application/; gleam test.

Might just be a small issue that someone with experience would have spotted right away, but the error was quite confusing to me as someone who hasn't worked in the erlang/beam ecosystem. Feel free to close this issue if it isn't that big of a problem.

lpil commented 1 year ago

Hello! I agree this is an unfortunate problem with how Erlang modules work. In this case the project overwrites the application module that is part of Erlang/OTP itself, causing the VM to crash when it attempts to use this module in some vital way.

We want to guard against this sharp edge for sure. Here's an issue that can be tracked: https://github.com/gleam-lang/gleam/issues/1267