Interpreting Dialyzer Messages

I’m using VS Code 1.23.0, Elixir 1.6.4… ElixirLS is giving me messages that don’t seem to make sense to me.

I’m using the ExAws.EC2 library. I’m calling the function describe_instance_status in the following way:

opts = [filters: ["event.code": "*"]]
EC2.describe_instance_status(opts)

ElixirLS Dialyzer reports:

	"severity": 4,
	"message": "The call 'Elixir.ExAws.EC2':describe_instance_status(Vopts@1::[{'filters',[{'event.code',<<_:8>>},...]},...]) breaks the contract (opts::describe_instance_status_opts()) -> 'Elixir.ExAws.Operation.Query':t()",

The spec for that function in the library is:

  @spec describe_instance_status() :: ExAws.Operation.Query.t
  @spec describe_instance_status(opts :: describe_instance_status_opts) :: ExAws.Operation.Query.t

The type is defined up above that spec as:

  @type describe_instance_status_opts :: [
    dry_run: boolean,
    filters: [filter, ...],
    include_all_instances: boolean,
    instance_ids: [binary, ...],
    max_results: integer,
    next_token: binary
  ]

The same problems show up running : mix dialyzer from command line. Can someone help me with interpreting what dialyzer is trying to tell me?

The filter is specified as:

 @type filter :: {name :: binary | atom, value :: [binary,...]}

Which means a value of "*" that you use does not match the type for the value. If aws supports using “*” as the filter, this is a bug in the type spec in the library.

2 Likes

OK, that makes sense. Thank you. AWS does support the * to match everything although its hidden pretty well in their doc. I’ll see if I can form in a way that aligns with the current spec and give feedback to the library authors.

Found that:

opts = [filters: ["event.code": ["*"]]]

works with AWS EC2 API and that approach matches the spec.

1 Like