MethodError For Defined Function

Hello,

I am back to using Julia, since more than 3 years break from the language.
So I may not be most up-to-date with the latest changes.

That said, I am using my package DanceJL and am running into a MethodError, for something trivial that worked before.

To keep things simple, I have only added 1 endpoint and function:

using Dance.Router

function get_string()
    return "hello"
end

println(methods(get_string))
println(get_string())

route("/post_dict", get_string; method=GET, endpoint=EP_HTML)

Then I call this endpoint via Postman, to get a Method Error.

As you can see I have added print statements to debug.
Output of above 2 is:

# 1 method for generic function "get_string" from Main.Backend:
 [1] get_string()
     @ ~Projects/Tracker/backend/routes.jl:3
hello

I have added another println(methods(route.action)) to where my package would be calling the newly defined function.
And have removed the headers input, to keep things simple.

Output is:

# 1 method for generic function "get_string" from Main.Backend:
 [1] get_string()
     @ ~Projects/Tracker/backend/routes.jl:3

As we can see the endpoint function is recognised.

=> Why do I still get a Method Error?

What’s the exact error message? What method is missing?

1 Like

Yeah. Always include the full error message with the stack trace.

It would also be a good idea to ask a question that doesn’t depend on your package. That is, reduce your example to something that doesn’t depend on external packages.

Exact error message I get is:

MethodError(Main.Backend.get_string, (), 0x0000000000006877)

As for stacktrace:

MethodError: no method matching get_string()
β”‚ The function `get_string` exists, but no method is defined for this combination of argument types.
β”‚ 
β”‚ Closest candidates are:
β”‚   get_string() (method too new to be called from this world context.)
β”‚    @ Main.Backend ~Projects/Tracker/backend/routes.jl:3
β”‚ 
β”‚ 9-element Vector{Base.StackTraces.StackFrame}:
β”‚  process_backend_function(; route::Dance.Router.Route, route_segments::Vector{String}, payload::String, headers::Dict{String, String}) at CoreEngine.jl:119
β”‚  process_backend_function at CoreEngine.jl:78 [inlined]
β”‚  render(; request_headers::Dict{String, String}, request_method::String, request_path::String, request_payload::String) at CoreEngine.jl:256
β”‚  render at CoreEngine.jl:217 [inlined]
β”‚  #2 at FlamencoEngine.jl:29 [inlined]
β”‚  macro expansion at Server.jl:104 [inlined]
β”‚  (::Flamenco.Server.var"#2#4"{Dance.CoreEngine.var"#2#3"})(x::Int64) at macros.jl:20
β”‚  (::ThreadPools.var"#_fn#54"{Flamenco.Server.var"#2#4"{Dance.CoreEngine.var"#2#3"}, ThreadPools.var"#start#53"{ThreadPools.var"#finish#51"{ThreadPools.var"#len#50"{Int64, Int64, Int64}}, ThreadPools.var"#len#50"{Int64, Int64, Int64}}, ThreadPools.var"#finish#51"{ThreadPools.var"#len#50"{Int64, Int64, Int64}}, Vector{Nothing}, Vector{Int64}})(ind::Int64) at staticpool.jl:49
β”‚  (::ThreadPools.var"#49#56"{ThreadPools.var"#_fn#54"{Flamenco.Server.var"#2#4"{Dance.CoreEngine.var"#2#3"}, ThreadPools.var"#start#53"{ThreadPools.var"#finish#51"{ThreadPools.var"#len#50"{Int64, Int64, Int64}}, ThreadPools.var"#len#50"{Int64, Int64, Int64}}, ThreadPools.var"#finish#51"{ThreadPools.var"#len#50"{Int64, Int64, Int64}}, Vector{Nothing}, Vector{Int64}}, Int64})() at macros.jl:261
β”” @ Dance.CoreEngine ~/.julia/packages/Dance/eo9RS/src/engines/CoreEngine.jl:126

So I suppose key takeaway is method too new to be called from this world context.

Thank you

Solved by adding Base.invokelatest