<commit_before>-type ddTimestamp() :: 'undefined' | {integer(), integer(), integer()}.
-type ddDatetime() :: 'undefined' | {{integer(), integer(), integer()},{integer(), integer(), integer()}}.

-define(MatchAllRecords,[{'$1', [], ['$_']}]).
-define(MatchAllKeys,[{'$1', [], [{element,2,'$1'}]}]).

-define(sot,'$start_of_table').		%% defined in mnesia, signals start of fetch transaction here 
-define(eot,'$end_of_table').		  %% defined in mnesia, signals end of fetch transaction here

-define(THROW_EXCEPTION(__Ex,__Reason),
    (fun() ->
        __Level = case __Ex of
            'UnimplementedException' -> warning;
            'ConcurrencyException' ->   warning;
            'ClientError' ->            warning;
            _ ->                        error
        end,
        _Rsn = __Reason,
        {__Head,__Fields} = case _Rsn of
            __Rsn when is_tuple(__Rsn) ->
                [__H|__R] = tuple_to_list(__Rsn),
                case __R of
                    []  -> {__H,[]};
                    __R when is_tuple(__R) ->
                        __RL = tuple_to_list(__R),
                        {__H, lists:zip([list_to_atom("ep"++integer_to_list(__N)) || __N <- lists:seq(1,length(__RL))], __RL)};
                    __R -> {__H,__R}
                end;
            __Else -> {__Level,[{ep1,__Else}]}
        end,            
        __Message = if 
            is_atom(__Head) -> list_to_binary(atom_to_list(__Head));
            is_list(__Head) -> list_to_binary(__Head);
            true            -> <<"invalid exception head">>
        end,
        {_, {_,[_|__ST]}} = (catch erlang:now(1)),
        {__Module,__Function} = imem_meta:failing_function(__ST),
        __LogRec = #ddLog{logTime=erlang:now(),logLevel=__Level,pid=self()
                            ,module=__Module,function=__Function,node=node()
                            ,fields=[{ex,__Ex}|__Fields],message= __Message
                            ,stacktrace = __ST},
        catch imem_meta:write_log(__LogRec),
        case __Ex of
            'SecurityViolation' ->  exit({__Ex,__Reason});
            _ ->                    throw({__Ex,__Reason})
        end
    end)()
).

-define(ClientError(__Reason), ?THROW_EXCEPTION('ClientError',__Reason)).
-define(ClientErrorNoLogging(__Reason), throw({'ClientError',__Reason})).
-define(SystemException(__Reason),  ?THROW_EXCEPTION('SystemException',__Reason)).
-define(SystemExceptionNoLogging(__Reason), throw({'SystemException',__Reason})).
-define(ConcurrencyException(__Reason),  ?THROW_EXCEPTION('ConcurrencyException',__Reason)).
-define(UnimplementedException(__Reason),  ?THROW_EXCEPTION('UnimplementedException',__Reason)).

-record(ddLog,                              %% log table    
                  { logTime                 ::ddTimestamp()             %% erlang timestamp {Mega,Sec,Micro}
                  , logLevel                ::atom()
                  , pid                     ::pid()      
                  , module                  ::atom()
                  , function                ::atom()
                  , line=0                  ::integer()<commit_msg>fix in exception macros<commit_after>-type ddTimestamp() :: 'undefined' | {integer(), integer(), integer()}.
-type ddDatetime() :: 'undefined' | {{integer(), integer(), integer()},{integer(), integer(), integer()}}.

-define(MatchAllRecords,[{'$1', [], ['$_']}]).
-define(MatchAllKeys,[{'$1', [], [{element,2,'$1'}]}]).

-define(sot,'$start_of_table').		%% defined in mnesia, signals start of fetch transaction here 
-define(eot,'$end_of_table').		  %% defined in mnesia, signals end of fetch transaction here

-ifdef(LAGER).
  -define(LAGER_WARNING(__Warn),lager:warning("~p",[__Warn])).
-else. % CONSOLE
  -define(LAGER_WARNING(__Warn),io:format(user,"~p~n",[__Warn])).
-endif. %LAGER or CONSOLE


-define(THROW_EXCEPTION(__Ex,__Reason),
    (fun() ->
        __Level = case __Ex of
            'UnimplementedException' -> warning;
            'ConcurrencyException' ->   warning;
            'ClientError' ->            warning;
            _ ->                        error
        end,
        _Rsn = __Reason,
        {__Head,__Fields} = case _Rsn of
            __Rsn when is_tuple(__Rsn) ->
                [__H|__R] = tuple_to_list(__Rsn),
                case __R of
                    []  -> {__H,[]};
                    __R when is_tuple(__R) ->
                        __RL = tuple_to_list(__R),
                        {__H, lists:zip([list_to_atom("ep"++integer_to_list(__N)) || __N <- lists:seq(1,length(__RL))], __RL)};
                    __R -> {__H,__R}
                end;
            __Else -> {__Level,[{ep1,__Else}]}
        end,            
        __Message = if 
            is_atom(__Head) -> list_to_binary(atom_to_list(__Head));
            is_list(__Head) -> list_to_binary(__Head);
            true            -> <<"invalid exception head">>
        end,
        {_, {_,[_|__ST]}} = (catch erlang:now(1)),
        {__Module,__Function} = imem_meta:failing_function(__ST),
        __LogRec = #ddLog{logTime=erlang:now(),logLevel=__Level,pid=self()
                            ,module=__Module,function=__Function,node=node()
                            ,fields=[{ex,__Ex}|__Fields],message= __Message
                            ,stacktrace = __ST},
        catch imem_meta:write_log(__LogRec),
        ?LAGER_WARNING(__LogRec),
        case __Ex of
            'SecurityViolation' ->  exit({__Ex,__Reason});
            _ ->                    throw({__Ex,__Reason})
        end
    end)()
).

-define(ClientError(__Reason), ?THROW_EXCEPTION('ClientError',__Reason)).
-define(ClientErrorNoLogging(__Reason), throw({'ClientError',__Reason})).
-define(SystemException(__Reason),  ?THROW_EXCEPTION('SystemException',__Reason)).
-define(SystemExceptionNoLogging(__Reason), throw({'SystemException',__Reason})).
-define(ConcurrencyException(__Reason),  ?THROW_EXCEPTION('ConcurrencyException',__Reason)).
-define(UnimplementedException(__Reason),  ?THROW_EXCEPTION('UnimplementedException',__Reason)).

-record(ddLog,                              %% log table    
                  { logTime                 ::ddTimestamp()             %% erlang timestamp {Mega,Sec,Micro}
                  , logLevel                ::atom()
                  , pid                     ::pid()      
                  , module                  ::atom()
                  , function                ::atom()
                  , line=0                  ::integer()
{'fraction_non_alphanumeric': 0.15006905017646155, 'fraction_numerical': 0.0024551173852999848, 'mean_word_length': 1.983066361556064, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1957705', 'n_tokens_mistral': 1936, 'n_tokens_neox': 1859, 'n_words': 302}