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

Patching BIFs fails with MatchError #73

Open
ollien opened this issue Dec 8, 2024 · 0 comments
Open

Patching BIFs fails with MatchError #73

ollien opened this issue Dec 8, 2024 · 0 comments

Comments

@ollien
Copy link

ollien commented Dec 8, 2024

Hiya!

I may be running into a "this cannot be supported" situation, but the failure mode was somewhat surprising.

For a small project I was trying to patch Kernel.node/0, but ran into trouble (the patch seemingly had no effect). I assumed this might be because Kernel.node/0 is inlined by the compiler and tried this on a whim, but got the following MatchError (truncated for readability; you can find the full error here)

  test "can patch node" do
    patch(:erlang, :node, :me@localhost)

    assert Kernel.node() == :me@localhost
  end
** (MatchError) no match of right hand side value: {:error, {:abstract_forms_invalid, ...}}
     code: patch(:erlang, :node, :me@localhost)
     stacktrace:
       (patch 0.14.0) lib/patch.ex:492: Patch.patch/3
       (patch 0.14.0) lib/patch.ex:507: Patch.patch/3
       test/user/patch/erlang_test.exs:28: (test)

I took a quick stab at fixing it, but found myself out of my depth somewhat quickly; this seems to boil down to this error from :compile.abstract_forms/2. At least one of these errors (the :undefined_function) seems legitimate and not suitable to ignore, so I am unsure of a decent path forward.

   [
     {~c"erlang.erl",
      [
        {{57, 2}, :erl_lint, {:bad_deprecated, {:now, 0}}},
        {{60, 2}, :erl_lint, {:bad_deprecated, {:phash, 2}}},
        {{1411, 2}, :erl_lint, {:undefined_function, {:halt, 2}}}
      ]}
   ],

I acknowledge, I am probably doing something that would not be best practice for writing a test :) The easy solution is to wrap my node check in a mockable function, but I wanted to report this behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant