instructure/canvas-lms · error · PeerReview::StudentIdsRequiredError
Student ids are required
Error message
Student ids are required
What it means
PeerReview::StudentIdsRequiredError raised by validate_student_ids_required when student_ids is nil, an empty string, a whitespace-only string, or an empty array. At least one target student is needed to create peer reviews.
Solutions
- Pass a non-empty array of student ids (e.g. [101, 102])
- Fix the client to require at least one selected student before submit
- Verify the param key name matches what the service expects
Example fix
// before service.call(student_ids: params[:students] || []) # empty array // after return unless params[:students].present? service.call(student_ids: params[:students].map(&:to_i))
Defensive patterns
Strategy: validation
Validate before calling
raise ArgumentError, 'student_ids must be a non-empty array' if student_ids.nil? || (student_ids.respond_to?(:empty?) && student_ids.empty?) || student_ids.to_s.strip.empty?
Try / catch
begin
service.call(student_ids:)
rescue PeerReview::StudentIdsRequiredError => e
render json: { error: e.message }, status: :bad_request
end Prevention
- Enforce at-least-one-student selection in the UI before submit
- Convert whitespace strings to arrays/ints early and re-check for emptiness
- Use consistent param naming (student_ids) across client and service
When it happens
Trigger: Calling a peer review creation service with student_ids: nil, '', ' ', or []; passing params[:student_ids] when the request body omitted the field.
Common situations: Frontend submits with no students selected; array filtered down to empty before the call; JSON payload uses wrong key so student_ids stays nil.
Understand the failure class
Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.
Related errors
- Set id is required
- Set type is required
- Course does not exist
- Override does not exist
- Peer review due date cannot be after assignment until date
AI-assisted analysis of instructure/canvas-lms@1c9f0bb801 (2026-09-15).
Data as JSON: /api/errors/04add3117d8be8b0.
Report an issue: GitHub.
Appendix: source
Thrown at app/services/peer_review/validations.rb:216
def validate_set_id_required(set_id)
raise PeerReview::SetIdRequiredError, I18n.t("Set id is required") unless set_id.present?
end
def validate_override_exists(override)
raise PeerReview::OverrideNotFoundError, I18n.t("Override does not exist") unless override.present?
end
def validate_section_exists(section)
raise PeerReview::SectionNotFoundError, I18n.t("Section does not exist") unless section.present?
end
def validate_course_exists(course)
raise PeerReview::CourseNotFoundError, I18n.t("Course does not exist") unless course.present?
end
def validate_student_ids_required(student_ids)
if student_ids.nil? || student_ids == "" || student_ids.to_s.strip.empty? || (student_ids.is_a?(Array) && student_ids.empty?)
raise PeerReview::StudentIdsRequiredError, I18n.t("Student ids are required")
end
end
def validate_student_ids_in_course(student_ids)
raise PeerReview::StudentIdsNotInCourseError, I18n.t("Student ids are not in course") if student_ids.blank?
end
def validate_set_type_supported(set_type, services)
unless services.key?(set_type)
supported_types = services.keys.join(", ")
raise PeerReview::SetTypeNotSupportedError,
I18n.t("Set type '%{set_type}' is not supported. Supported types are: %{supported_types}", set_type:, supported_types:)
end
end
def validate_group_assignment_required(assignment)
unless assignment.group_category_id
raise PeerReview::GroupAssignmentRequiredError, I18n.t("Must be a group assignment to create group overrides")View on GitHub (pinned to 1c9f0bb801)