title: Catching SQL error on future failure in Slick
body: <p>The code below uses Slick 3.1.x to read a row from a table, attempting to catch any SQL errors. <code>UserDB</code> is the Slick representation of the table, and <code>User</code> is the related object.</p>
  
  <p>This code does not compile in the <code>failure</code> statement with the following error:</p>
  
  <blockquote>
    <p>type mismatch; found : Unit required:
    scala.concurrent.Future[Option[user.manage.User]]</p>
  </blockquote>
  
  <p>How to fix this to catch the SQL error?</p>
  
  <pre><code>   def read (sk: Int): Future[Option[User]] = {
        val users = TableQuery[UserDB]
        val action = users.filter(_.sk === sk).result
        val future = db.run(action)
        future.onSuccess {
          case result =&gt;
                if (!result.isEmpty)
                    Some(result(0))
                else
                    None
        }
        future.onFailure {   // &lt;-- compilation error
            case e =&gt; println (e.getMessage)
            None
        }
     }
  </code></pre>