 
   selectRandomWorkflow: (project) ->
     linkedActiveWorkflows = project.links.active_workflows
-    if linkedActiveWorkflows.length > 0
+    if linkedActiveWorkflows?.length > 0
       randomIndex = Math.floor Math.random() * linkedActiveWorkflows.length
       # console.log 'Chose random workflow', linkedActiveWorkflows[randomIndex]
       linkedActiveWorkflows[randomIndex]
     else
-      throw new Error "No workflows for project #{project.id}"
-      project.uncacheLink 'workflows'
+      @workflowSelectionErrorHandler()
+
 
   getWorkflow: (selectedWorkflowID, activeFilter = true) ->
     query =

          @setState({ loadingSelectedWorkflow: false, workflow })
        else
          console.log "No workflow #{selectedWorkflowID} for project #{@state.project.id}"
          if @props.location.query?.workflow?
            @context.router.push "/projects/#{@state.project.slug}/classify"
          @clearInactiveWorkflow(selectedWorkflowID)
            .then(@getSelectedWorkflow(@state.project, @state.preferences))

  clearInactiveWorkflow: (selectedWorkflowID) ->
    preferences = @state.preferences

      preferences.save()
    else
      Promise.resolve(null)

  workflowSelectionErrorHandler: () ->
    throw new Error "No active workflows for project #{@state.project.id}"
    @state.project.uncacheLink 'workflows'

  checkUserRoles: (project, user) ->
    currentUserRoleSets = @state.projectRoles.filter((roleSet) => roleSet.links.owner.id is user?.id)
