<commit_before>Common debugging/error/exception functions and template haskell versions that give file location information

# Error/undefined

    > $(err "OH NO!")
    main:Main main.hs:16:1 OH NO!


Notice how it displays package:module file:line:character
It exposes the functions err (error), undef (undefined), and trc (Debug.Trace.trace). All of these behave the same as their normal counterpart but also spit out a location.

    > $undef
    main:Main test/main.hs:10:5 undefined
    main: Prelude.undefined

2 other error functions are included- fromJst and fromRht.

    > $fromJst Nothing
    main:Main test/main.hs:27:4 fromJst: Nothing

# Debug helpers

I also included my favorite helper, debug, which is like trace but just show the value.

    > debug [1,2,3]
    DEBUG: [1,2,3]
    [1,2,3]


There is a version without the DEBUG prefix called both strace and traceId.
And Here is the TH version of debug `dbg`:

    > $dbg [1,2,3]
    DEBUG main:Main main.hs:1:3 [1,2,3]
    [1,2,3]


Additionally there is a debugMsg and a TH function `dbgMsg` can be used to add a message prefix:

    > $(dbgMsg "the list") [1,2,3]
    DEBUG main:Main main.hs:1:3 the list: [1,2,3]
    [1,2,3]


Also there is debugM for stand-alone use in a monad. There is also functions ltrace and ltraceM (short for labeled trace)- it is like debug, but you tell it what string to print out instead of "DEBUG".


# Exceptions

Also there is a version of thrwIO that gives location information. thrwsIO takes appends a string to the file locaiton information.

    import Control.Exception.Base (Exception(..))
    import Prelude hiding (catch)
    import Control.Exception.Control (throwIO, catch)

    data AException = AException String deriving (Show, Typeable)
    instance Exception AException

    ($(thrwIO) AException) `catch` \e -> putStrLn ("Caught " ++ show (e :: AException))
    
    Caught AException "main:Main test/main.hs:25:6"

# Test Suite

./test/run.sh
<commit_msg>add a note about reThrow<commit_after>Common debugging/error/exception functions and template haskell versions that give file location information

# Error/undefined

    > $(err "OH NO!")
    main:Main main.hs:16:1 OH NO!


Notice how it displays package:module file:line:character
It exposes the functions err (error), undef (undefined), and trc (Debug.Trace.trace). All of these behave the same as their normal counterpart but also spit out a location.

    > $undef
    main:Main test/main.hs:10:5 undefined
    main: Prelude.undefined

2 other error functions are included- fromJst and fromRht.

    > $fromJst Nothing
    main:Main test/main.hs:27:4 fromJst: Nothing

# Debug helpers

I also included my favorite helper, debug, which is like trace but just show the value.

    > debug [1,2,3]
    DEBUG: [1,2,3]
    [1,2,3]


There is a version without the DEBUG prefix called both strace and traceId.
And Here is the TH version of debug `dbg`:

    > $dbg [1,2,3]
    DEBUG main:Main main.hs:1:3 [1,2,3]
    [1,2,3]


Additionally there is a debugMsg and a TH function `dbgMsg` can be used to add a message prefix:

    > $(dbgMsg "the list") [1,2,3]
    DEBUG main:Main main.hs:1:3 the list: [1,2,3]
    [1,2,3]


Also there is debugM for stand-alone use in a monad. There is also functions ltrace and ltraceM (short for labeled trace)- it is like debug, but you tell it what string to print out instead of "DEBUG".


# Exceptions

Also there is a version of thrwIO that gives location information. thrwsIO takes appends a string to the file locaiton information.

    import Control.Exception.Base (Exception(..))
    import Prelude hiding (catch)
    import Control.Exception.Control (throwIO, catch)

    data AException = AException String deriving (Show, Typeable)
    instance Exception AException

    ($(thrwIO) AException) `catch` \e -> putStrLn ("Caught " ++ show (e :: AException))
    
    Caught AException "main:Main test/main.hs:25:6"

Just added: `reThrow`. It catches exceptions, stamps some file location information onto it, and re-throws the exception. Note that  the file-location information is only for the reThrow usage site, it is still best to use `thrwIO` if you control the creation of the exception.

# Test Suite

./test/run.sh

{'fraction_non_alphanumeric': 0.08883129123468426, 'fraction_numerical': 0.020735155513666354, 'mean_word_length': 3.6546052631578947, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6085158', 'n_tokens_mistral': 1343, 'n_tokens_neox': 1278, 'n_words': 550}