gleam-lang / gleam

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

gleam cant find elixir.app when using finch in a project. #2396

Closed Bamii closed 11 months ago

Bamii commented 1 year ago

lpil commented 1 year ago

Hello! I'm having trouble reproducing this. Could you share more information please?

What operating system are you using? How did you install Gleam and Elixir? Could you share everything Gleam prints to the console after you run gleam run 🙏

Thank you

Bamii commented 1 year ago

@lpil OS: Windows 11 Installed Gleam & Elixir using scoop

so, its even crazier because if i create a new project and just do these steps... it works fine. but on this one project i'm working on, it breaks. (and i just found out i don't need to import the library, mere installing it breaks the program)

gleam.toml

version = "0.1.0"
gleam = ">= 0.32.0"

[dependencies]
gleam_stdlib = "~> 0.31"
gleam_http = "~> 3.5"
gleam_json = "~> 0.6"
gleam_erlang = "~> 0.22"
gleam_hackney = "~> 1.1"
finch_gleam = "~> 4.0"

[dev-dependencies]
gleeunit = "~> 0.10"

sequence of events i took to reproduce:

PS C:\Users\ACER-PC\Documents\work\openai> gleam remove finch_gleam  // to make sure its uninstalled.
    Removed finch_gleam

PS C:\Users\ACER-PC\Documents\work\openai> gleam run
  Compiling openai
   Compiled in 0.44s
    Running openai.main
body!!
"{\"model\":\"gpt-3.5-turbo\",\"messages\":[{\"role\":\"user\",\"content\":\"conjugate these words === avoir, etre, defiler, entrer ===\"}],\"mod
el\":\"gpt-3.5-turbo\"}"

PS C:\Users\ACER-PC\Documents\work\openai> gleam add finch_gleam
  Resolving versions
Downloading packages
 Downloaded 9 packages in 0.13s
      Added finch_gleam v4.0.0

PS C:\Users\ACER-PC\Documents\work\openai> gleam run
  Resolving versions
  Compiling hpax
  Compiling castore
  Compiling mint
  Compiling mime
  Compiling telemetry
===> Analyzing applications...
===> Compiling telemetry
  Compiling nimble_options
  Compiling nimble_pool
  Compiling finch
warning: Logger.warn/1 is deprecated. Use Logger.warning/2 instead
  lib/finch/http2/pool.ex:362: Finch.HTTP2.Pool.connected/3

warning: Logger.warn/1 is deprecated. Use Logger.warning/2 instead
  lib/finch/http2/pool.ex:460: Finch.HTTP2.Pool.connected_read_only/3

  Compiling finch_gleam

warning: Deprecated BitString name used
  ┌─ C:\Users\ACER-PC\Documents\work\openai\build\packages\finch_gleam\src\finch\stream.gleam:7:14
  │
7 │   Data(data: BitString)
  │              ^^^^^^^^^

The type BitString has been renamed to BitArray.

Hint: Run `gleam fix` to auto-fix your code.

warning: Deprecated type import
  ┌─ C:\Users\ACER-PC\Documents\work\openai\build\packages\finch_gleam\src\finch\stream.gleam:1:23
  │
1 │ import finch/headers.{Headers as ReqHeaders}
  │                       ^^^^^^^

The syntax for importing a type has changed. The new syntax is:

    import module.{type Headers}

Hint: Run `gleam fix` to auto-fix your code.

warning: Deprecated type import
  ┌─ C:\Users\ACER-PC\Documents\work\openai\build\packages\finch_gleam\src\finch\otp.gleam:6:27
  │
6 │ import gleam/erlang/atom.{Atom}
  │                           ^^^^

The syntax for importing a type has changed. The new syntax is:

    import module.{type Atom}

Hint: Run `gleam fix` to auto-fix your code.

warning: Deprecated type import
  ┌─ C:\Users\ACER-PC\Documents\work\openai\build\packages\finch_gleam\src\finch\otp.gleam:5:19
  │
5 │ import gleam/map.{Map}
  │                   ^^^

The syntax for importing a type has changed. The new syntax is:

    import module.{type Map}

Hint: Run `gleam fix` to auto-fix your code.

warning: Deprecated type import
  ┌─ C:\Users\ACER-PC\Documents\work\openai\build\packages\finch_gleam\src\finch\otp.gleam:4:23
  │
4 │ import gleam/dynamic.{Dynamic}
  │                       ^^^^^^^

The syntax for importing a type has changed. The new syntax is:

    import module.{type Dynamic}

Hint: Run `gleam fix` to auto-fix your code.

warning: Deprecated type import
  ┌─ C:\Users\ACER-PC\Documents\work\openai\build\packages\finch_gleam\src\finch\otp.gleam:7:30
  │
7 │ import gleam/erlang/process.{Pid}
  │                              ^^^

The syntax for importing a type has changed. The new syntax is:

    import module.{type Pid}

Hint: Run `gleam fix` to auto-fix your code.

warning: Deprecated type import
  ┌─ C:\Users\ACER-PC\Documents\work\openai\build\packages\finch_gleam\src\finch\otp.gleam:8:23
  │
8 │ import finch/timeout.{Timeout}
  │                       ^^^^^^^

The syntax for importing a type has changed. The new syntax is:

    import module.{type Timeout}

Hint: Run `gleam fix` to auto-fix your code.

warning: Deprecated type import
   ┌─ C:\Users\ACER-PC\Documents\work\openai\build\packages\finch_gleam\src\finch.gleam:14:22
   │
14 │ import finch/stream.{StreamFun}
   │                      ^^^^^^^^^

The syntax for importing a type has changed. The new syntax is:

The syntax for importing a type has changed. The new syntax is:

    import module.{type InstanceOptions}

Hint: Run `gleam fix` to auto-fix your code.

warning: Deprecated type import
   ┌─ C:\Users\ACER-PC\Documents\work\openai\build\packages\finch_gleam\src\finch.gleam:13:23
   │
13 │ import finch/headers.{Headers}
   │                       ^^^^^^^

The syntax for importing a type has changed. The new syntax is:

    import module.{type Headers}

Hint: Run `gleam fix` to auto-fix your code.
   Compiled in 15.44s
    Running openai.main
exception error: no match of right hand side value 
                 {error,{elixir,{"no such file or directory","elixir.app"}}}

PS C:\Users\ACER-PC\Documents\work\openai> gleam fix
Your Gleam code has been fixed!

If you have any JavaScript code that used the BitString class
you will need to update it to use the BitArray class instead.

PS C:\Users\ACER-PC\Documents\work\openai> gleam run
  Compiling openai

warning: Unused imported module
  ┌─ C:\Users\ACER-PC\Documents\work\openai\src\api.gleam:4:1
  │
4 │ import chat/models as chat_models
  │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ This imported module is never used.

Hint: You can safely remove it.
   Compiled in 0.47s
    Running openai.main
exception error: no match of right hand side value
                 {error,{elixir,{"no such file or directory","elixir.app"}}}
lpil commented 1 year ago

Very strange. Could you share what the openai module looks like?

Bamii commented 1 year ago

inside src/ all the files are empty... except

fortunewang commented 12 months ago

I get the same issue when I run gleam run without Administrator terminal at first.

  1. Create a hello-world project
  2. Run gleam add floki (adds an Elixir dependency)
  3. Run gleam run. This will fail by creating symbol link build/dev/erlang/eex without Administrator privilege. But build/dev/erlang/gleam_elixir_paths still exists as if build/dev/erlang/{eex, elixir, logger, mix} was successful created.
  4. Open an Administrator terminal, run gleam run again. Symbol link build/dev/erlang/floki is created. Starting OTP application floki will fail because application elixir does not exist at build/dev/erlang/elixir.

To fix it, remove build/dev/erlang/gleam_elixir_paths, edit some source codes to force re-compiling.

lpil commented 11 months ago

Ah fantastic, that's really useful! Thank you so much!

lpil commented 11 months ago

Would you be able to test tomorrow with the nightly build please? 🙏

fortunewang commented 11 months ago

I don't know if @Bamii 's trouble was caused by the privilege issue, but the privilege issue isn't fix by 11146add8e63f51a9d82d463b91901528766b71f

The problem is, normal users cannot create symbol links on Windows. This limitation is introduced by system api CreateSymbolicLinkW.

Maybe we could remove build/{target}/erlang/gleam_elixir_paths if failed creating symbol links at https://github.com/gleam-lang/gleam/blob/11146add8e63f51a9d82d463b91901528766b71f/compiler-core/src/build/package_compiler.rs#L530 and warn the lacking of privilege on windows

Or append Elixir's ebin paths with -pa <ebin path> separately when gleam run, instead of creating their symbol links together with dependencies?

lpil commented 11 months ago

Oh I see! Sorry, I have misunderstood the problem. I thought the symlink operation was silently failing, but instead it was that it fails but the build tool did not clean up the directories as required.

Would you be able to show me what the error looks like?

Adding the Elixir ebin paths is a great idea! It's not trivial to implement that so I'll make an issue for it.

fortunewang commented 11 months ago

Outputs of normal user:

~/projects $ gleam new hello
Your Gleam project hello has been successfully created.
The project can be compiled and tested by running these commands:

        cd hello
        gleam test

~/projects $ cd hello
~/projects/hello $ gleam add floki
  Resolving versions
Downloading packages
 Downloaded 3 packages in 0.08s
      Added floki v0.35.2
~/projects/hello $ gleam run
  Resolving versions
  Compiling gleam_stdlib
  Compiling gleeunit
  Compiling floki
error: File IO failure

An error occurred while trying to link this file:

    D:\home\fw\projects\hello\build\dev\erlang\eex

The error message from the file IO library was:

    客户端没有所需的特权。 (os error 1314)

~/projects/hello $

The chinese words means "A required privilege is not held by the client."

Outputs of Administrator terminal:

~/projects/hello # gleam run
  Compiling floki
  Compiling hello
   Compiled in 3.62s
    Running hello.main
exception error: no match of right hand side value
                 {error,{elixir,{"no such file or directory","elixir.app"}}}
~/projects/hello # gleam clean
~/projects/hello # gleam run
Downloading packages
 Downloaded 3 packages in 0.06s
  Compiling gleam_stdlib
  Compiling floki
  Compiling gleeunit
  Compiling hello
   Compiled in 5.52s
    Running hello.main
Hello from hello!
~/projects/hello #
lpil commented 11 months ago

Thank you. Does using the nightly now result in the error happening every time gleam build is run without the elevated permissions?

fortunewang commented 11 months ago

Every time.

~/projects/hello $ git -C ~\projects\gleam log --oneline -n 1
6ac9134 (HEAD -> main, origin/main, origin/HEAD) Prompt to create git tags
~/projects/hello $ ~\projects\gleam\target\release\gleam.exe run
Downloading packages
 Downloaded 3 packages in 0.06s
  Compiling gleam_stdlib
d:/home/fw/projects/hello/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@float.erl:166:21: Warning: this clause cannot match because a previous clause at line 165 always matches
%  166|                     -0.0 -> -0.0;
%     |                     ^

  Compiling gleeunit
  Compiling floki
error: Fatal compiler bug!

This is a bug in the Gleam compiler, sorry!

Please report this crash to https://github.com/gleam-lang/gleam/issues/new
with this information and the code that produces the crash.

        D:\home\fw\projects\gleam\compiler-core\src\build\elixir_libraries.rs:53
        deleting paths cache in cleanup: FileIo { kind: Directory, action: Delete, path: "D:\\home\\fw\\projects\\hello\\build\\dev\\erlang\\gleam_elixir_paths", err: Some("目录名称无效。 (os error 267)") }
~/projects/hello $ ~\projects\gleam\target\release\gleam.exe run
  Compiling floki
error: File IO failure

An error occurred while trying to link this file:

    D:\home\fw\projects\hello\build\dev\erlang\floki

The error message from the file IO library was:

    客户端没有所需的特权。 (os error 1314)

~/projects/hello $ ~\projects\gleam\target\release\gleam.exe run
  Compiling floki
error: File IO failure

An error occurred while trying to link this file:

    D:\home\fw\projects\hello\build\dev\erlang\floki

The error message from the file IO library was:

    客户端没有所需的特权。 (os error 1314)

~/projects/hello $

Still the same, with https://github.com/gleam-lang/gleam/pull/2422

~/projects/hello $ rm -rf build\
~/projects/hello $ git -C ~\projects\gleam log --oneline -n 1
a5e0f52 (HEAD -> main, origin/main, origin/HEAD) Fix: `delete` should be `delete_file`
~/projects/hello $ ~\projects\gleam\target\release\gleam.exe run
Downloading packages
 Downloaded 3 packages in 0.07s
  Compiling floki
error: File IO failure

An error occurred while trying to link this file:

    D:\home\fw\projects\hello\build\dev\erlang\eex

The error message from the file IO library was:

    客户端没有所需的特权。 (os error 1314)

~/projects/hello $ ~\projects\gleam\target\release\gleam.exe run
  Compiling gleam_stdlib
d:/home/fw/projects/hello/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@float.erl:166:21: Warning: this clause cannot match because a previous clause at line 165 always matches
%  166|                     -0.0 -> -0.0;
%     |                     ^

  Compiling gleeunit
  Compiling floki
error: File IO failure

An error occurred while trying to link this file:

    D:\home\fw\projects\hello\build\dev\erlang\eex

The error message from the file IO library was:

    客户端没有所需的特权。 (os error 1314)

~/projects/hello $ ~\projects\gleam\target\release\gleam.exe run
  Compiling floki
error: File IO failure

An error occurred while trying to link this file:

    D:\home\fw\projects\hello\build\dev\erlang\eex

The error message from the file IO library was:

    客户端没有所需的特权。 (os error 1314)

~/projects/hello $ ~\projects\gleam\target\release\gleam.exe run
  Compiling floki
error: File IO failure

An error occurred while trying to link this file:

    D:\home\fw\projects\hello\build\dev\erlang\eex

The error message from the file IO library was:

    客户端没有所需的特权。 (os error 1314)

~/projects/hello $  
lpil commented 11 months ago

Thank you