jeremyjh / dialyxir

Mix tasks to simplify use of Dialyzer in Elixir projects.
Apache License 2.0
1.7k stars 140 forks source link

Ignore Erlang module or silence errors #435

Closed Doerge closed 9 months ago

Doerge commented 3 years ago

Precheck

Environment

Elixir 1.12.2 (compiled with Erlang/OTP 24)


* Which version of Dialyxir are you using? (cat mix.lock | grep dialyxir):

"dialyxir": {:hex, :dialyxir, "1.1.0", "c5aab0d6e71e5522e77beff7ba9e08f8e02bad90dfbeffae60eaf0cb47e29488", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "07ea8e49c45f15264ebe6d5b93799d4dd56a44036cf42d0ad9c960bc266c0b9a"},


### Current behavior
I get this output when running `mix dialyzer`:

Finding suitable PLTs Checking PLT... [...] PLT is up to date! ignore_warnings: .dialyzer_ignore.exs

Starting Dialyzer [ check_plt: false, init_plt: '.../_build/dev/dialyxir_erlang-24.0.3_elixir-1.12.2_deps-dev.plt', files: [ ...], warnings: [:unknown] ] [...]


Please file a bug in https://github.com/jeremyjh/dialyxir/issues with this message.

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

Legacy warning: src/EconomicWebService.WSDL.xml_client.erl:11238:1: Function 'GetApiInformation'/3 has no local return


Please file a bug in https://github.com/jeremyjh/dialyxir/issues with this message.

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

Legacy warning: src/EconomicWebService.WSDL.xml_client.erl:11239:67: The call soap_client_util:call(Soap_body::any(),Soap_headers::any(),Options::any(),"\"\"",{'interface',[69 | 83 | 87 | 98 | 99 | 101 | 105 | 109 | 110 | 111 | 114 | 118,...],'EconomicWebService.WSDL.xml','1.2','soap_client_inets','soap_server_cowboy_1','undefined','EconomicWebService.WSDL.xml_client',[],[45 | 46 | 47 | 58 | 99 | 101 | 104 | 105 | 109 | 110 | 111 | 112 | 116,...],[1..255,...],'undefined','undefined',[1..255,...],[1..255,...],[1..255,...],[1..255,...],[{'op',[any(),...],atom(),[],'undefined','requestresponse',atom(),atom(),'undefined'},...],{'model',[{,,,,,,,,,,,},...],[{,,,_},...],[45 | 46 | 47 | 58 | 99 | 101 | 104 | 105 | 109 | 110 | 111 | 112 | 116,...],[],'false','skip'},1,'undefined',[{[any(),...],[any(),...]},...]}) will never return since the success typing is (tuple(),[any()],[{'url',string()}],string(),{'interface',string(),atom(),'1.1' | '1.2',atom(),atom(),atom(),atom(),[any()],string(),string(),'undefined' | string(),'undefined' | [{[any()],'module'}],string(),string(),string(),string(),[{'op',[any()],atom(),[any()],'undefined' | [any()],'notification' | 'requestresponse',atom() | [any()],atom() | [any()],[any()]}],{'model',,,,,,_},integer(),'undefined' | string(),[{[any()],'undefined' | [any()]}]}) -> {'error',{'client',{'httprequest',} | {'encodingbody',,_} | {'parsingmessage',,maybe_improperlist(),,}} | {'server',integer(),[{,_}]},maybe_improper_list(binary() | maybe_improper_list(any(),binary() | []) | byte(),binary() | [])} and the contract is (Body::tuple(),Headers::[any()],Options::[option()],Soap_action::string(),interface()) -> soap_response()


done (warnings were emitted) Halting VM with exit status 2


In my Elixir/Phoenix project I call a Soap endpoint that I have generated an Erlang client for using https://github.com/bet365/soap
The above errors originate in this Erlang module.

I don't really expect Dialyzer/Dialyxir to check this module. I would be happy if I could just silence them instead.

However specifying this in my dialyzer_ignore.exs file doesn't work:

[ {"src/EconomicWebService.WSDL.xml_client.erl"} ]



How can I either tell Dialyxir to ignore these erlang files, or alternatively just silence the warnings?

(PS: Thanks for a great project! 👏 )
drathier commented 3 years ago

We might have hit the same issue with code generated by the erlang backend for purescript. We've tried ignoring the errors but dialyzer_ignore.ex doesn't work, and we're getting hundreds of these errors since it's in generated code.

Please file a bug in https://github.com/jeremyjh/dialyxir/issues with this message.
Unknown error occurred: %Protocol.UndefinedError{description: "", protocol: String.Chars, value: {49, 5}}
Legacy warning:
/workspace/.spago/datetime/v5.0.2-erl1/src/Data/DateTime/Instant.purs:49:5: The variable _ can never match since previous clauses completely covered the type any()

Code in question:

-file("/workspace/.spago/datetime/v5.0.2-erl1/src/Data/DateTime/Instant.purs", 49).
-spec unInstant() -> fun((any()) -> any()).
unInstant() -> fun (V) ->
  case V of
    (_@0) -> _@0
  end
end.
-file("/workspace/.spago/datetime/v5.0.2-erl1/src/Data/DateTime/Instant.purs", 49).
-spec unInstant(any()) -> any().
unInstant(_@1) -> case _@1 of
  (_@2) -> _@2
end.

generated from this purescript code:

newtype Instant
  = Instant Milliseconds

unInstant (Instant ms) = ms

Thanks for the project, let me know if I can help further!

marcelotto commented 3 years ago

I'm getting the same error in a project with some parsers generated with Erlang's leex and yecc:


Please file a bug in https://github.com/jeremyjh/dialyxir/issues with this message.

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

Legacy warning:
/usr/local/Cellar/erlang/20.0/lib/erlang/lib/parsetools-2.1.5/include/leexinc.hrl:276:1: Function yyrev/2 will never be called
________________________________________________________________________________
Please file a bug in https://github.com/jeremyjh/dialyxir/issues with this message.

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

Legacy warning:
/usr/local/Cellar/erlang/20.0/lib/erlang/lib/parsetools-2.1.5/include/yeccpre.hrl:60:26: Call to missing or unexported function erlang:get_stacktrace/0
jeremyjh commented 3 years ago

If anyone can provide a repo I can check out and reproduce this error I will be happy to take a look.

marcelotto commented 3 years ago

The errors I've reported are from https://github.com/rdf-elixir/rdf-ex.

However, I'm only getting them locally (under Elixir 1.12.2 and OTP 24.0.1), but not on CI with the same versions, which makes me wonder if my local setup is somehow broken, especially with the paths in the warnings pointing to /usr/local/Cellar/erlang/20.0/. I'm using the Erlang plugin for asdf locally, and I'm not experiencing any other issues with this setup otherwise. 🤔

jeremyjh commented 3 years ago

@marcelotto I wasn't able to reproduce it locally using those versions of Erlang/Elixir (with asdf). My guess is there is a stale PLT file; by default we create a new PLT for each different version of Erlang/Elixir but that project is using a single-hard coded file per its mix.exs, if you just delete priv/plts/dialyzer.plt and re-run it my guess is it will work.

marcelotto commented 3 years ago

My bad. I assumed that mix dialyzer.clean would do that. Sorry for the noise. And thanks for the check and the hint (and maintaining this great project in general).

jeremyjh commented 3 years ago

Ah, thats actually a bug if it doesn't.

marcelotto commented 3 years ago

Before you start investigating further, let me try a manual cleanup when I'm back home. I just answered your last comment quickly during a break in my day job.

marcelotto commented 3 years ago

Ok, mix dialyzer.clean successfully deletes the PLT file. So, I guess something else in my local environment must be the cause.

Doerge commented 3 years ago

@jeremyjh Thanks for replying!

I've made a repro repo here: https://github.com/Doerge/dialyxir-bug-repro/commits/master

Am I doing something obvious wrong with Dialyxir/Dialyzer?

marcelotto commented 3 years ago

Although unrelated to this issue, I thought I share the final solution to the occurrence of this error in the context of leex and yecc parsers, just if someone else stumbles across this issue from this direction: due to this open Elixir issue, the Erlang parsers from the leex and yecc grammars were generated under an older Erlang version and got never cleaned up. After deleting the generated Erlang files in src/ manually, so they could be regenerated under the current version, everything worked fine.

Nezteb commented 1 year ago

If anyone can provide a repo I can check out and reproduce this error I will be happy to take a look.

@jeremyjh Someone on the Elixir Slack reached out to me about a PR of theirs and I was able to reproduce it: https://github.com/lexical-lsp/lexical/pull/217

If you want to chat about this and discuss a solution, let me know!