Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FunctionClauseError: no function clause matching in Lightning.Projects.projects_for_user_query/1 #1318

Closed
sentry-io bot opened this issue Nov 9, 2023 · 1 comment · Fixed by #1394
Assignees
Labels
bug Newly identified bug question Further information is requested

Comments

@sentry-io
Copy link

sentry-io bot commented Nov 9, 2023

This appears to happen whenever someone tries to do somehthing but their session token is no longer valid. They get redirected to the login page on the front-end. How should we handle these in Elixir and Sentry?

Sentry Issue: LIGHTNING-1C

FunctionClauseError: no function clause matching in Lightning.Projects.projects_for_user_query/1
  File "lib/lightning/projects.ex", line 350, in Lightning.Projects.projects_for_user_query/1
  File "lib/lightning/projects.ex", line 359, in Lightning.Projects.get_projects_for_user/1
  File "lib/lightning_web/hooks.ex", line 23, in LightningWeb.Hooks.on_mount/4
  File "lib/phoenix_live_view/lifecycle.ex", line 149, in anonymous fn/4 in Phoenix.LiveView.Lifecycle.mount/3
  File "lib/phoenix_live_view/lifecycle.ex", line 212, in Phoenix.LiveView.Lifecycle.reduce_socket/3
...
(3 additional frame(s) were not displayed)

(FunctionClauseError no function clause matching in Lightning.Projects.projects_for_user_query/1)
@sentry-io sentry-io bot added the question Further information is requested label Nov 9, 2023
@taylordowns2000 taylordowns2000 added the bug Newly identified bug label Nov 9, 2023
@stuartc
Copy link
Member

stuartc commented Nov 15, 2023

This is an interesting one, because the router does correctly redirect users that don't have a session anymore - but it seems like the socket is still connected or at least the "request" is a LiveView request.

In InitAssigns we assume the user is logged in; because "hey that's handled upstream". And I'm not convinced that we should handle redirection there either.

However, the actual line where things break is:

def on_mount(:project_scope, %{"project_id" => project_id}, _session, socket) do
  %{current_user: current_user} = socket.assigns

  project = Lightning.Projects.get_project(project_id)

  projects = Lightning.Projects.get_projects_for_user(current_user) # <= HERE
  #...
end

I think there is quite a bit we can improve with our routing/on_mount hooks here.

But for now I think it would be ok for us to redirect inside the :project_scope hook, if there is no current_user on the socket. I'd recommend pattern matching for it in a clause above the current one.

@midigofrank midigofrank self-assigned this Nov 15, 2023
stuartc added a commit that referenced this issue Nov 30, 2023
Redirect when current_user not available in project_scope hook

Fixes: #1318 
---------

Co-authored-by: Stuart Corbishley <corbish@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Newly identified bug question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants