Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Crystal::Loader errors #11860

Merged

Conversation

straight-shoota
Copy link
Member

@straight-shoota straight-shoota commented Feb 28, 2022

This patch improves error messages from dlopen. They're now also shown for lib arguments (-lfoo) which was missing. Also adds fault tolerance when dlerror returns a null pointer.

/ref #11857

Comment on lines +26 to +31
new(String.build do |io|
io << message
io << " ("
io.write_string(Slice.new(char_pointer, LibC.strlen(char_pointer)))
io << ")"
end)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using String.build here to avoid two intermediary string allocations. Maybe that's overkill for error handling...

@jeffbdavenport
Copy link

jeffbdavenport commented Feb 28, 2022

Trying to test out this code. And I cannot even run crystal i with this branch @asterite @straight-shoota

jeff@jeffs-machine project (master)$ crystal i
In /usr/local/share/crystal/src/prelude.cr:51:1

 51 | require "hash"
      ^
Error: while requiring "hash"


In /usr/local/share/crystal/src/hash.cr:1:1

 1 | require "crystal/hasher"
     ^
Error: while requiring "crystal/hasher"


In /usr/local/share/crystal/src/crystal/hasher.cr:83:27

 83 | Crystal::System::Random.random_bytes(Slice.new(pointerof(@@seed).as(UInt8*), sizeof(typeof(@@seed))))
                              ^-----------
Error: instantiating 'Crystal::System::Random:Module#random_bytes(Slice(UInt8))'


In /usr/local/share/crystal/src/crystal/system/unix/getrandom.cr:41:5

 41 | init unless @@initialized
      ^---
Error: instantiating 'init()'


In /usr/local/share/crystal/src/crystal/system/unix/getrandom.cr:27:8

 27 | if sys_getrandom(Bytes.new(16)) >= 0
         ^------------
Error: instantiating 'sys_getrandom(Slice(UInt8))'


In /usr/local/share/crystal/src/crystal/system/unix/getrandom.cr:93:5

 93 | loop do
      ^---
Error: instantiating 'loop()'


In /usr/local/share/crystal/src/crystal/system/unix/getrandom.cr:93:5

 93 | loop do
      ^---
Error: instantiating 'loop()'


In /usr/local/share/crystal/src/crystal/system/unix/getrandom.cr:94:80

 94 | read_bytes = Syscall.getrandom(buf.to_unsafe, LibC::SizeT.new(buf.size), Syscall::GRND_NONBLOCK)
                                                                               ^---------------------
Error: undefined constant Syscall::GRND_NONBLOCK

@straight-shoota
Copy link
Member Author

Looks as if your master branch is out of sync. This bug was fixed in #11624.

@beta-ziliani beta-ziliani added this to the 1.4.0 milestone Mar 2, 2022
@straight-shoota straight-shoota merged commit 416c478 into crystal-lang:master Mar 4, 2022
@straight-shoota straight-shoota deleted the feature/loader-error branch March 4, 2022 10:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants