r12543

r12543

Getting UndefinedFunctionError for a variable, even after it is well defined

Hello,
I am getting the following error. Code is also mentioned below.

%UndefinedFunctionError{arity: 0, function: :offset, message: nil, module: nil, reason: nil}

{offset, _} = Integer.parse(headers["upload-offset"]). # headers["upload-offset"] returns a valid result everytime. "0", "452342" etc
upload_info = UploadCache.get(identifier)
if  offset != upload_info.offset do. # here it crashes and throw the error.
        ... # doing something here
else

This does not happen every time. I found this issue in the production sometimes and I am not even able to reproduce this on my local machine. Can anyone give their inputs in what scenarios, this type of error can occur?


Stack trace

msg:Ranch listener OkApi.Router.HTTP, connection process #PID<0.19205.307>, stream 3 had its request process #PID<0.18116.307> exit with reason {{%UndefinedFunctionError{arity: 0, function: :offset, message: nil, module: nil, reason: nil}, 
[{nil, :offset, 
[],
[]}, {ExTus.Actions, :patch, 3, 
  [file: 'lib/actions.ex', line: 81]}, {OkApi.TusRouter, :"-do_match/4-fun-7-", 2, 
  [file: 'lib/routers/tus_router.ex', line: 25]}, {OkApi.TusRouter, :dispatch, 2, 
  [file: 'lib/plug/router.ex', line: 284]}, {OkApi.TusRouter, :plug_builder_call, 2, 
  [file: 'lib/routers/tus_router.ex', line: 1]}, {Plug, :forward, 4, 
  [file: 'lib/plug.ex', line: 168]}, {OkApi.Router, :dispatch, 2, 
  [file: 'lib/plug/router.ex', line: 284]}, {OkApi.Router, :plug_builder_call, 2, 
  [file: 'lib/Router.ex', line: 1]}]}, {OkApi.Router, :call, 
  [%Plug.Conn{adapter: {Plug.Cowboy.Conn, :...}, assigns: %{}, before_send: 
  [], body_params: %Plug.Conn.Unfetched{aspect: :body_params}, cookies: %Plug.Conn.Unfetched{aspect: :cookies}, halted: false, host: "<some-host>", method: "PATCH", owner: #PID<0.18116.307>, params: %Plug.Conn.Unfetched{aspect: :params}, path_info: 
  ["files", "<identifier>"], path_params: %{}, port: 80, private: %{}, query_params: %Plug.Conn.Unfetched{aspect: :query_params}, query_string: "", remote_ip: {..., .., ., ...}, req_cookies: %Plug.Conn.Unfetched{aspect: :cookies}, req_headers: 
  h=[
    {"accept-encoding", "gzip"}, 
    {"authorization", "<jwt_token>"}, 
    {"connection", "keep-alive"}, 
    {"content-type", "application/offset+octet-stream"}, 
    {"host", "<some-host>.com"}, 
    {"migration_ver", "2"}, 
    {"newrelic", "...."}, 
    {"traceparent", "..."}, 
    {"tracestate", ",..."}, 
    {"tus-resumable", "1.0.0"}, 
    {"upload-metadata", "filename Y2JiMjA2OTgtZGNmYy00MTgwLWE3M2MtYzYxMGZjOTg5YWE5Lm1wNA=="}, 
    {"upload-offset", "0"}, 
    {"user-agent", "Dalvik/2.1.0 (Linux; U; Android 9; CPH2083 Build/PPR1.180610.011)"}, 
    {"user_id", "....."}, 
    {"x-forwarded-for", "....."}, 
    {"x-forwarded-port", "443"}, 
    {"x-forwarded-proto", "https"}, 
    {"x-newrelic-id", "....."}
  ], request_path: "/files/<identifier>", resp_body: nil, resp_cookies: %{}, resp_headers: 
  [{"cache-control", "max-age=0, private, must-revalidate"}], scheme: :http, script_name: 
  [], secret_key_base: nil, state: :unset, status: nil}, 
  []]}} and stacktrace 
  []

This is an open source function, here is the link extus/actions.ex at 273f8b15588743787ca8a9abcb9d815ee2c9f8ae · bluzky/extus · GitHub

Thanks

Marked As Solved

michallepicki

michallepicki

The error is about upload_info being nil. nil.offset fails with that error

Where Next?

Popular in Questions Top

gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
hpopp
To simplify some tasks at work, I wrote and published this package yesterday. It’s a simple macro that enables Access behaviour on struct...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
lucidguppy
I have a super simple question about elixir - how would I take a file like this foo bar baz and output a new file that enumerates th...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New

Other popular topics Top

sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 45766 226
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
qwerescape
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
lucidguppy
I have a super simple question about elixir - how would I take a file like this foo bar baz and output a new file that enumerates th...
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
273 38985 115
New

We're in Beta

About us Mission Statement