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

Faulty nil checks after using a find method #2128

Open
damianhxy opened this issue Mar 24, 2024 · 0 comments · May be fixed by #2139
Open

Faulty nil checks after using a find method #2128

damianhxy opened this issue Mar 24, 2024 · 0 comments · May be fixed by #2139

Comments

@damianhxy
Copy link
Member

In at least several controllers, .nil? checks are performed after calling .find( ... ). However, find throws an exception if an id is not found, so the checks are never reached.

They should be replaced with find_by where possible.

Some instances (found with grep -nr ".find(" -A 2)

course_user_data_controller.rb

    @editCUD = @course.course_user_data.find(params[:id])
    if @editCUD.nil?
      flash[:error] = "Can't find user in the course"
      redirect_to(action: "index") && return
    end

groups_controller.rb

    ass = @course.assessments.find(params[:ass])
    if !ass
      flash[:error] = "Assessment not found."
      redirect_to(action: :index) && return

users_controller.rb

    user = User.find(params[:id])
    if user.nil?
      flash[:error] = "Failed to edit user: user does not exist."
      redirect_to(users_path) && return
    end

lti_nrps_controller.rb

    lcd = LtiCourseDatum.find(params[:lcd_id])
    if lcd.nil? || lcd.membership_url.nil? || lcd.course_id.nil?
      raise LtiLaunchController::LtiError.new("Unable to update roster", :bad_request)
    end
@coder6583 coder6583 linked a pull request Apr 1, 2024 that will close this issue
2 tasks
@coder6583 coder6583 linked a pull request Apr 1, 2024 that will close this issue
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants