<commit_before>:- module(main, []).

/** <module> The main module */

:- use_module(library(bc/bc_env)).

% Catch uncaught errors/warnings and shut down
% when they occur.

:- dynamic(loading/1).
:- asserta(loading(0)).

% The first hook is for detecting
% loading state.

user:message_hook(Term, _, _):-
    (   Term = load_file(start(Level, _))
    ->  asserta(loading(Level))
    ;   (   Term = load_file(done(Level, _, _, _, _, _))
        ->  retractall(loading(Level))
        ;   true)),
    fail.

% The second hook shuts down SWI when
% error occurs during loading.

:- if(bc_env_production).
    user:message_hook(Term, Type, _):-
        loading(_),
        ( Type = error ; Type = warning ),
        message_to_string(Term, String),
        writeln(user_error, String),
        halt(1).
:- endif.

:- use_module(library(bc/bc_main)).
:- use_module(library(bc/bc_type)).
:- use_module(lib/routes).
:- use_module(lib/config).
:- use_module(library(bc/bc_router)).
:- use_module(library(bc/bc_data)).
:- use_module(library(http/http_unix_daemon)).
:- use_module(library(http/thread_httpd)).

% Enables preview for posts.

:- bc_register_preview(post, '/post/<slug>').

% Initialize the serving daemon.

http_unix_daemon:http_server_hook(Options):-
    http_server(bc_route, Options).

:- dynamic(started/0).

start:-
    started, !.

start:-
    config(db, File),
    bc_data_open(File),
    http_daemon,
    assertz(started).

:- start.<commit_msg>Better solution for detecting load-time errors<commit_after>:- module(main, []).

/** <module> The main module */

:- use_module(library(bc/bc_env)).

:- dynamic(started/0).

% Catch uncaught errors/warnings before start and shut down
% when they occur.

user:message_hook(Term, Type, _):-
    \+ started,
    ( Type = error ; Type = warning ),
    message_to_string(Term, String),
    writeln(user_error, String),
    halt(1).

:- use_module(library(bc/bc_main)).
:- use_module(library(bc/bc_type)).
:- use_module(lib/routes).
:- use_module(lib/config).
:- use_module(library(bc/bc_router)).
:- use_module(library(bc/bc_data)).
:- use_module(library(http/http_unix_daemon)).
:- use_module(library(http/thread_httpd)).

% Enables preview for posts.

:- bc_register_preview(post, '/post/<slug>').

% Initialize the serving daemon.

http_unix_daemon:http_server_hook(Options):-
    http_server(bc_route, Options),
    assertz(started).

start:-
    started, !.

start:-
    config(db, File),
    bc_data_open(File),
    http_daemon.

:- start.
{'fraction_non_alphanumeric': 0.1636654661864746, 'fraction_numerical': 0.0024009603841536613, 'mean_word_length': 3.646840148698885, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '1227259', 'n_tokens_mistral': 885, 'n_tokens_neox': 877, 'n_words': 156}