Cannot import Pdf.Inspector.validate_file/1 because it doesn't exist

Hi all
I want to import a function from a module and the compiler complains:

cannot import Pdf.Inspector.validate_file/1 because it doesn’t exist

And do not why.

The module implementation:

def validate_file(path) do

    {_, code} = System.cmd("gs", ["-o /dev/null", "-sDEVICE=nullpage", path])
    valid_file?(code)
    
end

And the import

defmodule Pdf.Server do

  import Pdf.Inspector, only: [validate_file: 1]
  use GenServer

  def handle_call(path, _from, state) do
    res = validate_file(path)
    {:reply, res, state}
  end

end

What am I doing wrong?
Thanks

Can you gist the full Pdf.Inspector module?

2 Likes

Sorry I’ve forgot to post:

defmodule Pdf.Inspector do

  @spec validate_file(String.t) :: {:ok} | {:error}
  def validate_file(path) do

    {_, code} = System.cmd("gs", ["-o /dev/null", "-sDEVICE=nullpage", path])
    valid_file?(code)

  end

  @spec count_pages(String.t) :: integer
  def count_pages(path) do

    {res, _} = System.cmd("gs", ["-q", "-dNODISPLAY", "-c", ~s/(#{path}) (r) file runpdfbegin pdfpagecount = quit/])

    res
    |> String.split("\n")
    |> process

  end

  @spec process([String.t]) :: integer
  defp process(list) do
    search_page_number(list)
  end

  defp search_page_number([h|t]) do

    try do
      String.to_integer(h)
    rescue
      ArgumentError -> search_page_number(h)
    end

  end

  defp search_page_number([])  do
    0
  end

  defp valid_file?(0) do
    {:ok}
  end

  defp valid_file?(1) do
    {:error}
  end

end

Based on the given code it does not look like anything is wrong. In that case we may need a SSCCE (a simple example that demonstrates the issue that we can git clone)?

1 Like

The file structure looks like this

When I try alias instead import and it compiles:

defmodule Pdf.Server do

  #import Pdf.Inspector, only: [validate_file: 1]
  alias Pdf.Inspector
  use GenServer


  def handle_call(path, _from, state) do
    #res = validate_file(path)
    #{:reply, res, state}
  end

end

Very strength.

It works here is the thing:

iex5> import Pdf.Inspector, only: [validate_file: 1]
Pdf.Inspector

So an SSCCE that we can git clone would let us look at it for sure. :slight_smile:

Ok I will do it. Wait a second.

1 Like

Here we go https://github.com/kostonstyle/simpleinspector

You have a Elixir.Pdf.Inspector.beam sitting in your root directory that is overriding the module.

1 Like

So what do I have to do?

Delete it.

Also as a side note you don’t want _build or deps checked into a git project.

1 Like

I know, I uploaded without thinking about it.
How can that happen of the Elixir.Pdf.Inspector.beam file, that sitting on the root.

Possibly you compiled a file manually or used the c helper inside iex? not sure.

3 Likes

Yeah maybe. Thanks so much.