<commit_before># -*- coding: UTF-8
# datainit.py: database initialization
#   ******************
import json

import os

from globaleaks import models
from globaleaks.orm import transact
#from globaleaks.handlers.submission import db_assign_submission_sequence
from globaleaks.handlers.admin.field import db_create_field
from globaleaks.rest import errors
from globaleaks.settings import GLSettings


def load_appdata():
    if os.path.exists(GLSettings.appdata_file):
        with file(GLSettings.appdata_file, 'r') as f:
            json_string = f.read()
            appdata_dict = json.loads(json_string)
            return appdata_dict

    raise errors.InternalServerError("Unable to load application data")


def load_default_fields(store):
    if os.path.exists(GLSettings.fields_path):
        for fname in os.listdir(GLSettings.fields_path):
            fpath = os.path.join(GLSettings.fields_path, fname)
            with file(fpath, 'r') as f:
                json_string = f.read()
                field_dict = json.loads(json_string)
                db_create_field(store, field_dict, None)
                return

    raise errors.InternalServerError("Unable to load default fields")
<commit_msg>Fix exception handling of default fields loader<commit_after># -*- coding: UTF-8
# datainit.py: database initialization
#   ******************
import json

import os

from globaleaks import models
from globaleaks.orm import transact
#from globaleaks.handlers.submission import db_assign_submission_sequence
from globaleaks.handlers.admin.field import db_create_field
from globaleaks.rest import errors
from globaleaks.settings import GLSettings


def load_appdata():
    if os.path.exists(GLSettings.appdata_file):
        with file(GLSettings.appdata_file, 'r') as f:
            json_string = f.read()
            appdata_dict = json.loads(json_string)
            return appdata_dict

    raise errors.InternalServerError("Unable to load application data")


def load_default_fields(store):
    try:
        if os.path.exists(GLSettings.fields_path):
            for fname in os.listdir(GLSettings.fields_path):
                fpath = os.path.join(GLSettings.fields_path, fname)
                with file(fpath, 'r') as f:
                    json_string = f.read()
                    field_dict = json.loads(json_string)
                    db_create_field(store, field_dict, None)
    except Exception as e:
        raise errors.InternalServerError("Unable to load default fields: %s" % e)

{'fraction_non_alphanumeric': 0.09210526315789473, 'fraction_numerical': 0.0007974481658692185, 'mean_word_length': 3.06645056726094, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3495445', 'n_tokens_mistral': 725, 'n_tokens_neox': 712, 'n_words': 182}