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

Unknown error occurred: %Protocol.UndefinedError{description: "", protocol: String.Chars, value: {47, 1}} #444

Closed
rlipscombe opened this issue Oct 11, 2021 · 1 comment · Fixed by #526

Comments

@rlipscombe
Copy link

rlipscombe commented Oct 11, 2021

Precheck

  • Take a look at the open issues and be sure that your issue is not already covered. -- I found a couple of vaguely-related issues, but none on point.
  • Be sure your versions of Dialyxir and Erlex are up to date. -- Yes.

Environment

  • Elixir & Erlang/OTP versions (elixir --version): 1.12.3 / OTP-24.0.6

  • Which version of Dialyxir are you using? (cat mix.lock | grep dialyxir): 1.0.0 (also fails with 1.1.0)

Current behavior

Running mix dialyze on a combined Erlang and Elixir project, I get the following error on my Erlang modules:

Unknown error occurred: %Protocol.UndefinedError{description: "", protocol: String.Chars, value: {47, 1}}

I strongly suspect that it's due to the fact that the "line number" in Erlang BEAM files now contains the column number (cf erlang-lager/lager#558), and this is tripping dialyxir up.

If I use --format raw, I don't get the error. If I use --format short, I see lib/dialyxir/formatter.ex:73: Dialyxir.Formatter.format_warning/2 in the stack trace.

@rlipscombe
Copy link
Author

The following patch against 1.1.0 fixes it:

diff --git a/lib/dialyxir/formatter.ex b/lib/dialyxir/formatter.ex
index 6aa9c38..4034f29 100644
--- a/lib/dialyxir/formatter.ex
+++ b/lib/dialyxir/formatter.ex
@@ -70,7 +70,7 @@ defmodule Dialyxir.Formatter do
     warning = warning(warning_name)
     string = warning.format_short(arguments)
 
-    "#{base_name}:#{line}:#{warning_name} #{string}"
+    "#{base_name}:#{format_line(line)}:#{warning_name} #{string}"
   end
 
   defp format_warning(dialyzer_warning = {_tag, {file, line}, message}, :dialyxir) do
@@ -83,7 +83,7 @@ defmodule Dialyxir.Formatter do
         string = warning.format_long(arguments)
 
         """
-        #{base_name}:#{line}:#{warning_name}
+        #{base_name}:#{format_line(line)}:#{warning_name}
         #{string}
         """
       rescue
@@ -138,6 +138,9 @@ defmodule Dialyxir.Formatter do
     formatted <> String.duplicate("_", 80)
   end
 
+  defp format_line({line, col}), do: "#{line}:#{col}"
+  defp format_line(line), do: "#{line}"
+
   defp wrap_error_message(message, warning) do
     """
     Please file a bug in https://github.com/jeremyjh/dialyxir/issues with this message.

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

Successfully merging a pull request may close this issue.

1 participant