<commit_before>{-# LANGUAGE DeriveDataTypeable, PatternGuards, RecordWildCards, ConstraintKinds #-}

-- | Errors seen by the user
module Development.Shake.Internal.Errors(
    ShakeException(..),
    throwM, throwImpure,
    errorInternal,
    errorStructured,
    errorNoRuleToBuildType, errorRuleDefinedMultipleTimes,
    errorMultipleRulesMatch, errorRuleRecursion, errorComplexRecursion, errorNoApply,
    errorDirectoryNotFile, errorNoHash
    ) where

import Data.Tuple.Extra
import Control.Exception.Extra
import Control.Monad.IO.Class
import General.Extra
import Data.Typeable
import Data.List.Extra
import Data.Maybe


throwM :: MonadIO m => SomeException -> m a
throwM = liftIO . throwIO

throwImpure :: SomeException -> a
throwImpure = throw


errorInternal :: Partial => String -> SomeException
errorInternal msg = toException $ ErrorCall $ unlines $
    ("Development.Shake: Internal error, please report to Neil Mitchell (" ++ msg ++ ")") : callStackFull

alternatives = let (*) = (,) in
    ["_rule_" * "oracle"
    ,"_Rule_" * "Oracle"
    ,"_key_" * "question"
    ,"_Key_" * "Question"
    ,"_result_" * "answer"
    ,"_Result_" * "Answer"
    ,"_addBuiltinRule_" * "addOracle"
    ,"_apply_" * "askOracle"]


errorStructured :: String -> [(String, Maybe String)] -> String -> SomeException
errorStructured msg args hint = toException $ ErrorCall $ unlines $
        [msg ++ ":"] ++
        ["  " ++ a ++ [':' | a /= ""] ++ replicate (as - length a + 2) ' ' ++ b | (a,b) <- args2] ++
        [hint | hint /= ""]<commit_msg>Improve the display of errorStructured with no fields<commit_after>{-# LANGUAGE DeriveDataTypeable, PatternGuards, RecordWildCards, ConstraintKinds #-}

-- | Errors seen by the user
module Development.Shake.Internal.Errors(
    ShakeException(..),
    throwM, throwImpure,
    errorInternal,
    errorStructured,
    errorNoRuleToBuildType, errorRuleDefinedMultipleTimes,
    errorMultipleRulesMatch, errorRuleRecursion, errorComplexRecursion, errorNoApply,
    errorDirectoryNotFile, errorNoHash
    ) where

import Data.Tuple.Extra
import Control.Exception.Extra
import Control.Monad.IO.Class
import General.Extra
import Data.Typeable
import Data.List.Extra
import Data.Maybe


throwM :: MonadIO m => SomeException -> m a
throwM = liftIO . throwIO

throwImpure :: SomeException -> a
throwImpure = throw


errorInternal :: Partial => String -> SomeException
errorInternal msg = toException $ ErrorCall $ unlines $
    ("Development.Shake: Internal error, please report to Neil Mitchell (" ++ msg ++ ")") : callStackFull

alternatives = let (*) = (,) in
    ["_rule_" * "oracle"
    ,"_Rule_" * "Oracle"
    ,"_key_" * "question"
    ,"_Key_" * "Question"
    ,"_result_" * "answer"
    ,"_Result_" * "Answer"
    ,"_addBuiltinRule_" * "addOracle"
    ,"_apply_" * "askOracle"]


errorStructured :: String -> [(String, Maybe String)] -> String -> SomeException
errorStructured msg args hint = toException $ ErrorCall $ unlines $
        [msg ++ (if null args then "." else ":")] ++
        ["  " ++ a ++ [':' | a /= ""] ++ replicate (as - length a + 2) ' ' ++ b | (a,b) <- args2] ++
        [hint | hint /= ""]
{'fraction_non_alphanumeric': 0.1367819739765154, 'fraction_numerical': 0.0012694382735639479, 'mean_word_length': 3.7830045523520486, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4810805', 'n_tokens_mistral': 1008, 'n_tokens_neox': 961, 'n_words': 252}