# Buggy code
def _init_modules(args, crash_handler):
    """Initialize all 'modules' which need to be initialized.

    Args:
        args: The argparse namespace.
        crash_handler: The CrashHandler instance.
    """
    log.init.debug("Initializing save manager...")
    save_manager = savemanager.SaveManager(q_app)
    objreg.register("save-manager", save_manager)
    configinit.late_init(save_manager)

    log.init.debug("Checking backend requirements...")
    backendproblem.init()

    log.init.debug("Initializing prompts...")
    prompt.init()

    log.init.debug("Initializing network...")
    networkmanager.init()

    log.init.debug("Initializing proxy...")
    proxy.init()

    log.init.debug("Initializing readline-bridge...")
    readline_bridge = readline.ReadlineBridge()
    objreg.register("readline-bridge", readline_bridge)

    try:
        log.init.debug("Initializing sql...")
        sql.init(os.path.join(standarddir.data(), "history.sqlite"))

        log.init.debug("Initializing web history...")
        history.init(q_app)
    except sql.SqlEnvironmentError as e:
        error.handle_fatal_exc(
            e, args, "Error initializing SQL", pre_text="Error initializing SQL"
        )
        sys.exit(usertypes.Exit.err_init)

    log.init.debug("Initializing command history...")
    cmdhistory.init()

    log.init.debug("Initializing crashlog...")
    if not args.no_err_windows:
        crash_handler.handle_segfault()

    log.init.debug("Initializing sessions...")
    sessions.init(q_app)

    log.init.debug("Initializing websettings...")
    websettings.init(args)

    log.init.debug("Initializing quickmarks...")
    quickmark_manager = urlmarks.QuickmarkManager(q_app)
    objreg.register("quickmark-manager", quickmark_manager)

    log.init.debug("Initializing bookmarks...")
    bookmark_manager = urlmarks.BookmarkManager(q_app)
    objreg.register("bookmark-manager", bookmark_manager)

    log.init.debug("Initializing cookies...")
    cookie_jar = cookies.CookieJar(q_app)
    ram_cookie_jar = cookies.RAMCookieJar(q_app)
    objreg.register("cookie-jar", cookie_jar)
    objreg.register("ram-cookie-jar", ram_cookie_jar)

    log.init.debug("Initializing cache...")
    diskcache = cache.DiskCache(standarddir.cache(), parent=q_app)
    objreg.register("cache", diskcache)

    log.init.debug("Initializing downloads...")
    download_manager = qtnetworkdownloads.DownloadManager(parent=q_app)
    objreg.register("qtnetwork-download-manager", download_manager)

    log.init.debug("Initializing Greasemonkey...")
    greasemonkey.init()

    log.init.debug("Misc initialization...")
    macros.init()
    # Init backend-specific stuff
    browsertab.init()


# Traceback (qutebrowser.misc.sql.SqlEnvironmentError)
00:59:51 DEBUG    completion completionmodel:set_pattern:179 Setting completion pattern ''
00:59:51 DEBUG    sql        sql:__init__:174 Preparing SQL query: "SELECT url, title, strftime('%Y-%m-%d', last_atime, 'unixepoch', 'localtime') FROM CompletionHistory WHERE ((url || title) LIKE :0 escape '\')  ORDER BY last_atime DESC"
00:59:51 DEBUG    sql        sql:run:207 Running SQL query: "SELECT url, title, strftime('%Y-%m-%d', last_atime, 'unixepoch', 'localtime') FROM CompletionHistory WHERE ((url || title) LIKE :0 escape '\')  ORDER BY last_atime DESC"
00:59:51 DEBUG    sql        sql:run:210 query bindings: {':0': '%%'}
00:59:51 DEBUG    sql        sql:raise_sqlite_error:94 SQL error:
00:59:51 DEBUG    sql        sql:raise_sqlite_error:96 type: ConnectionError
00:59:51 DEBUG    sql        sql:raise_sqlite_error:97 database text: database disk image is malformed
00:59:51 DEBUG    sql        sql:raise_sqlite_error:98 driver text: Unable to fetch row
00:59:51 DEBUG    sql        sql:raise_sqlite_error:99 error code: 11
00:59:51 DEBUG    sql        debug:__exit__:265 Running completion query took 0.000379 seconds.
00:59:51 DEBUG    completion debug:__exit__:265 Set pattern  took 0.001134 seconds.
00:59:51 ERROR    misc       crashsignal:exception_hook:214 Uncaught exception
Traceback (most recent call last):
File "/usr/lib/python3.7/site-packages/qutebrowser/completion/completer.py", line 260, in _update_completion
completion.set_pattern(pattern)
File "/usr/lib/python3.7/site-packages/qutebrowser/completion/completionwidget.py", line 320, in set_pattern
self.model().set_pattern(pattern)
File "/usr/lib/python3.7/site-packages/qutebrowser/completion/models/completionmodel.py", line 185, in set_pattern
cat.set_pattern(pattern)
File "/usr/lib/python3.7/site-packages/qutebrowser/completion/models/histcategory.py", line 102, in set_pattern
str(i): w for i, w in enumerate(words)})
File "/usr/lib/python3.7/site-packages/qutebrowser/misc/sql.py", line 213, in run
self._check_ok('exec', ok)
File "/usr/lib/python3.7/site-packages/qutebrowser/misc/sql.py", line 196, in _check_ok
raise_sqlite_error(msg, error)
File "/usr/lib/python3.7/site-packages/qutebrowser/misc/sql.py", line 118, in raise_sqlite_error
raise SqlEnvironmentError(msg, error)
qutebrowser.misc.sql.SqlEnvironmentError: Failed to exec query "SELECT url, title, strftime('%Y-%m-%d', last_atime, 'unixepoch', 'localtime') FROM CompletionHistory WHERE ((url || title) LIKE :0 escape '\')  ORDER BY last_atime DESC": "database disk image is malformed Unable to fetch row"

# Fixed code
def _init_modules(args, crash_handler):
    """Initialize all 'modules' which need to be initialized.

    Args:
        args: The argparse namespace.
        crash_handler: The CrashHandler instance.
    """
    log.init.debug("Initializing save manager...")
    save_manager = savemanager.SaveManager(q_app)
    objreg.register("save-manager", save_manager)
    configinit.late_init(save_manager)

    log.init.debug("Checking backend requirements...")
    backendproblem.init()

    log.init.debug("Initializing prompts...")
    prompt.init()

    log.init.debug("Initializing network...")
    networkmanager.init()

    log.init.debug("Initializing proxy...")
    proxy.init()

    log.init.debug("Initializing readline-bridge...")
    readline_bridge = readline.ReadlineBridge()
    objreg.register("readline-bridge", readline_bridge)

    try:
        log.init.debug("Initializing sql...")
        sql.init(os.path.join(standarddir.data(), "history.sqlite"))

        log.init.debug("Initializing web history...")
        history.init(q_app)
    except sql.SqlKnownError as e:
        error.handle_fatal_exc(
            e, args, "Error initializing SQL", pre_text="Error initializing SQL"
        )
        sys.exit(usertypes.Exit.err_init)

    log.init.debug("Initializing command history...")
    cmdhistory.init()

    log.init.debug("Initializing crashlog...")
    if not args.no_err_windows:
        crash_handler.handle_segfault()

    log.init.debug("Initializing sessions...")
    sessions.init(q_app)

    log.init.debug("Initializing websettings...")
    websettings.init(args)

    log.init.debug("Initializing quickmarks...")
    quickmark_manager = urlmarks.QuickmarkManager(q_app)
    objreg.register("quickmark-manager", quickmark_manager)

    log.init.debug("Initializing bookmarks...")
    bookmark_manager = urlmarks.BookmarkManager(q_app)
    objreg.register("bookmark-manager", bookmark_manager)

    log.init.debug("Initializing cookies...")
    cookie_jar = cookies.CookieJar(q_app)
    ram_cookie_jar = cookies.RAMCookieJar(q_app)
    objreg.register("cookie-jar", cookie_jar)
    objreg.register("ram-cookie-jar", ram_cookie_jar)

    log.init.debug("Initializing cache...")
    diskcache = cache.DiskCache(standarddir.cache(), parent=q_app)
    objreg.register("cache", diskcache)

    log.init.debug("Initializing downloads...")
    download_manager = qtnetworkdownloads.DownloadManager(parent=q_app)
    objreg.register("qtnetwork-download-manager", download_manager)

    log.init.debug("Initializing Greasemonkey...")
    greasemonkey.init()

    log.init.debug("Misc initialization...")
    macros.init()
    # Init backend-specific stuff
    browsertab.init()