Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@dominicletz
Copy link
Contributor

When a nifs on_load function returns a non-ok value loading fails today silently without showing the returned error reason.

This is especially sad when the on_load callback is calling erlang:load_nif/2 as it lasts statement which many nif on_load callbacks do. erlang:load_nif/2 typically returns quite helpful error tuples that help to identify the reasons for why the nif failed loading. This change makes the error message appear in the output and in debug messages when debugging is enabled.

-on_load(init/0).

init() ->
    SoName = filename:join(code:priv_dir(?APPNAME), ?LIBNAME),
    erlang:load_nif(SoName, 0).

When a nifs `on_load` function returns a non-ok value loading fails today silently without showing the returned error reason. 

This is especially sad when the `on_load` callback is calling `erlang:load_nif/2` as it lasts statement which many nif `on_load` callbacks do. `erlang:load_nif/2` typically returns quite helpful error tuples that help to identify the reasons for why the nif failed loading. This change makes the error message appear in the output and in debug messages when debugging is enabled. 

```erlang
-on_load(init/0).

init() ->
    SoName = filename:join(code:priv_dir(?APPNAME), ?LIBNAME),
    erlang:load_nif(SoName, 0).
```
@rickard-green rickard-green added the team:VM Assigned to OTP team VM label Sep 14, 2021
@sverker
Copy link
Contributor

sverker commented Sep 21, 2021

This PR seems to address on_load failure in embedded mode. The code server used in interactive mode does already log a warning with the error included.

@sverker sverker added enhancement testing currently being tested, tag is used by OTP internal CI labels Sep 24, 2021
@sverker sverker merged commit 8a50ea6 into erlang:master Oct 19, 2021
@dominicletz dominicletz deleted the patch-4 branch October 19, 2021 21:33
@samwar
Copy link

samwar commented Feb 7, 2022

@sverker Curious, why hasn't this enhancement made it into an erlang release yet? I'm having some starting problems in embedded mode, and this fix would be a welcome addition to my debugging.

@sverker
Copy link
Contributor

sverker commented Feb 7, 2022

@samwar Because the PR was based on master branch and I did not ask for nor did myself a rebase on maint branch.

If you really want it for 24.3 do
git rebase --onto maint master
and supply a new PR referring this one.

@sverker
Copy link
Contributor

sverker commented Feb 7, 2022

OTP-24.3 is planned for March and 25.0 for May.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement team:VM Assigned to OTP team VM testing currently being tested, tag is used by OTP internal CI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants