title: ghci error: "No breakpoints found at that location."
body: <p>I am attempting to follow the <a href="https://downloads.haskell.org/~ghc/7.8.3/docs/html/users_guide/ghci-debugger.html" rel="nofollow noreferrer">ghci debugger documentation</a> to my stack project, and have entered the repl by running <code>$ stack ghci</code>. When I try to set a breakpoint at line 207 in module <code>Api.Checklist</code>, I get the following error.</p>
  
  <pre><code>&gt; :break Api.Checklist 207
  No breakpoints found at that location.
  </code></pre>
  
  <p>The breakpoint is not set, as shown by the empty result of <code>:show breaks</code>.</p>
  
  <pre><code>&gt; :show breaks
  No active breakpoints.
  </code></pre>
  
  <p>Why does <code>&gt; :break Api.Checklist 207</code> fail to set the breakpoint?</p>
  
  <hr>
  
  <p>EDIT:</p>
  
  <p>as requested, the content of Api.Checklist is below, where line <code>207</code> is the line reading <code>checklistAnswerPG entryId apiAnswer =</code>.</p>
  
  <pre><code>{-# LANGUAGE DataKinds             #-}
  {-# LANGUAGE DeriveGeneric         #-}
  {-# LANGUAGE DuplicateRecordFields #-}
  {-# LANGUAGE ExtendedDefaultRules  #-}
  {-# LANGUAGE FlexibleContexts      #-}
  {-# LANGUAGE TypeOperators         #-}
  
  module Api.Checklist where
  
  import           Control.Monad            (mapM, mapM_)
  import           Control.Monad.IO.Class   (liftIO)
  import           Data.Aeson               (FromJSON, Value(..),
                                             toJSON, encode)
  import qualified Data.HashMap.Strict      as M
  import           Data.Text                (Text, pack)
  import           Data.Time.Clock          (UTCTime, getCurrentTime)
  import           GHC.Generics             (Generic)
  import qualified Opaleye                  as O
  import           Servant
  
  import           Api.Shared
  import           App
  import           Models.Checklist
  import           Models.ChecklistAnswer
  import           Models.ChecklistEntry
  import           Models.ChecklistQuestion
  import           Models.ChecklistTemplate
  import           Models.Validation        (Errors(..), Validatable,
                                             Validation,
                                             ValidationResult (Failure, Success),
                                             errors, failure, keyToField,
                                             validate, validateEntity)
  import           Queries.Checklist
  import           Types.JWTUser
  
  data ApiAnswer = ApiAnswer { questionId :: Int, answer :: Maybe Bool }
    deriving (Generic)
  data ApiChecklistEntryWrite = ApiChecklistEntryWrite { answers :: [ApiAnswer] }
    deriving (Generic)
  
  instance FromJSON ApiAnswer
  instance FromJSON ApiChecklistEntryWrite
  instance Validatable ApiChecklistEntryWrite where
    validateEntity entry = do
      mapM_ validateAnswer $ answers entry
  
      where
        validateAnswer :: ApiAnswer -&gt; Validation
        validateAnswer apiAnswer = do
          case answer (apiAnswer :: ApiAnswer) of
            Just _ -&gt;
              return ()
  
            Nothing -&gt;
              failure (pack $ "answers[questionId=" ++ show (questionId (apiAnswer :: ApiAnswer)) ++ "]") ["must not be null"]
  
  
  type ChecklistAPI = Get '[JSON] ChecklistRead
                 :&lt;|&gt; ReqBody '[JSON] TemplateChecklist :&gt; Patch '[JSON] ChecklistRead
                 :&lt;|&gt; "entries" :&gt; Get '[JSON] [ChecklistEntryRead]
                 :&lt;|&gt; "entries" :&gt; Capture "checklistEntryId" Int :&gt; Get '[JSON] ChecklistEntryRead
                 :&lt;|&gt; "entries" :&gt; ReqBody '[JSON] ApiChecklistEntryWrite :&gt; Post '[JSON] ChecklistEntryRead
                 :&lt;|&gt; "questions" :&gt; Get '[JSON] [ChecklistQuestionRead]
                 :&lt;|&gt; "entries" :&gt; Capture "entryId" Int :&gt; "answers" :&gt; Get '[JSON] [Value]
  
  
  checklistAPI :: Servant.Proxy ChecklistAPI
  checklistAPI = Servant.Proxy
  
  
  checklistServer :: JWTUser -&gt; Int -&gt; ServerT ChecklistAPI AppM
  checklistServer jwtUser checklistId' = getChecklist jwtUser checklistId'
                                   :&lt;|&gt; updateChecklist jwtUser checklistId'
                                   :&lt;|&gt; getChecklistEntries jwtUser checklistId'
                                   :&lt;|&gt; getChecklistEntry jwtUser checklistId'
                                   :&lt;|&gt; createChecklistEntry jwtUser checklistId'
                                   :&lt;|&gt; getChecklistQuestions jwtUser checklistId'
                                   :&lt;|&gt; getChecklistAnswers jwtUser checklistId'
  
  
  getChecklist :: JWTUser -&gt; Int -&gt; AppM ChecklistRead
  getChecklist _ = singleQuery . checklistQuery
  
  
  updateChecklist :: JWTUser -&gt; Int -&gt; TemplateChecklist -&gt; AppM ChecklistRead
  updateChecklist jwtUser checklistId' template' = withTransaction $ do
    case validate template' of
      Success -&gt;
        go
  
      Failure es -&gt;
        throwError $ err422 { errBody = encode $ Errors { errors = es } }
  
    where
      go = do
        originalChecklist &lt;- singleQuery (checklistQuery checklistId')
        let facilityId' = facilityId (originalChecklist :: ChecklistRead)
            checklistWrite = ChecklistWrite { facilityId = facilityId'
                                            , name = name (template' :: TemplateChecklist)
                                            }
  
        updatedChecklist &lt;- liftIO . checklistToPG $ checklistWrite
        result &lt;- update
                  jwtUser
                  (Just facilityId')
                  checklistTable
                  (\_ -&gt; updatedChecklist { Models.Checklist.checklistId = Just $ O.pgInt4 checklistId' })
                  (\org -&gt; (Models.Checklist.checklistId org) O..== O.pgInt4 checklistId')
  
        case result of
          Left err -&gt;
            handleSqlError (keyToField template') err
  
          Right savedChecklist -&gt; do
            updateQuestions savedChecklist
            return savedChecklist
  
      updateQuestions savedChecklist = do
        let facilityId' = facilityId (savedChecklist :: ChecklistRead)
        now &lt;- liftIO getCurrentTime
        archivePreviousQuestions now facilityId'
        mapM_ (createQuestion savedChecklist now) $ questions template'
        return ()
  
      createQuestion :: ChecklistRead -&gt; UTCTime -&gt; TemplateQuestion -&gt; AppM ChecklistQuestionRead
      createQuestion savedChecklist now question' = do
        let facilityId' = facilityId (savedChecklist :: ChecklistRead)
        newChecklistQuestion &lt;-
          liftIO . checklistQuestionToPG now $ ChecklistQuestionWrite
                                               (checklistId (savedChecklist :: ChecklistRead))
                                               (question (question' :: TemplateQuestion))
                                               (description (question' :: TemplateQuestion))
                                               (questionType (question' :: TemplateQuestion))
                                               (position (question' :: TemplateQuestion))
        createOr500
          (keyToField template')
          jwtUser
          (Just facilityId')
          checklistQuestionTable
          newChecklistQuestion
  
      archivePreviousQuestions now facilityId' = do
        previousQuestions &lt;- query (checklistQuestionsByChecklistAndTimeQuery checklistId' now)
        mapM_ (archiveQuestion now facilityId') previousQuestions
  
      archiveQuestion :: UTCTime -&gt; Int -&gt; ChecklistQuestionRead -&gt; AppM ChecklistQuestionRead
      archiveQuestion now facilityId' question' = do
        updatedQuestion &lt;- liftIO . checklistQuestionReadToWrite $ question'
        updateOr500 (keyToField template') jwtUser (Just facilityId') checklistQuestionTable
                  (\_ -&gt; updatedQuestion { effectiveTo = O.pgUTCTime now })
                  (\q -&gt; Models.ChecklistQuestion.checklistQuestionId q O..== O.pgInt4 (Models.ChecklistQuestion.checklistQuestionId question'))
  
  
  
  getChecklistEntry :: JWTUser -&gt; Int -&gt; Int -&gt; AppM ChecklistEntryRead
  getChecklistEntry _ _ = singleQuery . checklistEntryQuery
  
  
  getChecklistEntries :: JWTUser -&gt; Int -&gt; AppM [ChecklistEntryRead]
  getChecklistEntries _  = query . checklistEntryByChecklistQuery
  
  
  getChecklistQuestions :: JWTUser -&gt; Int -&gt; AppM [ChecklistQuestionRead]
  getChecklistQuestions _ checklistId' =
    query . checklistQuestionsByChecklistAndTimeQuery checklistId' =&lt;&lt; liftIO getCurrentTime
  
  
  getChecklistAnswers :: JWTUser -&gt; Int -&gt; Int -&gt; AppM [Value]
  getChecklistAnswers _ _ id =
    fmap buildJson &lt;$&gt; (query $ checklistAnswersWithQuestionForChecklistEntryQuery id)
  
    where
      buildJson :: (ChecklistAnswerRead, ChecklistQuestionRead) -&gt; Value
      buildJson (a, q) =
        let
          Object jsonAnswer = toJSON a
          jsonQuestion = toJSON q
        in
          Object (M.insert "checklistQuestion" jsonQuestion jsonAnswer)
  
  
  createChecklistEntry :: JWTUser -&gt; Int -&gt; ApiChecklistEntryWrite -&gt; AppM ChecklistEntryRead
  createChecklistEntry jwtUser cId checklistEntryWrite = do
    checklist &lt;- singleQuery (checklistQuery cId) :: AppM ChecklistRead
    withTransaction $ validateAndCreate (go $ facilityId (checklist :: ChecklistRead)) checklistEntryWrite
  
    where
      go facId = do
        newChecklistEntry &lt;- liftIO . checklistEntryToPG $ ChecklistEntryWrite cId
        savedChecklistEntry &lt;- create jwtUser (Just facId) checklistEntryTable newChecklistEntry
  
        case savedChecklistEntry of
          Right checklistEntry -&gt; do
            let newChecklistAnswerPG = checklistAnswerPG $ checklistEntryId (checklistEntry :: ChecklistEntryRead)
  
            createdAnswers &lt;- mapM newChecklistAnswerPG $ answers checklistEntryWrite
            results &lt;- mapM (create jwtUser (Just facId) checklistAnswerTable) createdAnswers :: AppM [DbResult ChecklistAnswerRead]
            case all isRight results of
              True -&gt;
                return checklistEntry
              False -&gt;
                throwError $ err500 { errBody = "one or more answers failed to save" }
  
          Left _ -&gt;
            throwError err500
  
      checklistAnswerPG entryId apiAnswer =
        case answer (apiAnswer :: ApiAnswer) of
          Just a -&gt;
            liftIO $ checklistAnswerToPG $ ChecklistAnswerWrite { checklistEntryId = entryId
                                                                , checklistQuestionId = questionId apiAnswer
                                                                , answer = boolToText a
                                                                }
          Nothing -&gt;
            throwError $ err500 { errBody = "got a null answer, validations should have happened by now" }
  
      boolToText :: Bool -&gt; Text
      boolToText True  = "true"
      boolToText False = "false"
  </code></pre>