# Buggy code
def download_dir():
    """Get the download directory to use."""
    directory = config.val.downloads.location.directory
    remember_dir = config.val.downloads.location.remember

    if remember_dir and last_used_directory is not None:
        ddir = last_used_directory
    elif directory is None:
        ddir = standarddir.download()
    else:
        ddir = directory

    os.makedirs(ddir, exist_ok=True)

    return ddir


# Traceback (PermissionError)
15:48:51 DEBUG    downloads  qtnetworkdownloads:fetch:489 fetch: PyQt5.QtCore.QUrl('https://en.wikipedia.org/wiki/Canadian_National_Vimy_Memorial') -> Canadian_National_Vimy_Memorial
15:48:51 DEBUG    downloads  downloads:_on_begin_insert_row:825 _on_begin_insert_row with idx 0, webengine False
15:48:51 DEBUG    misc       standarddir:_writable_location:143 writable location for DownloadLocation: D:/
15:48:51 ERROR    misc       crashsignal:exception_hook:205 Uncaught exception
Traceback (most recent call last):
File "scripts/dev\..\..\scripts\..\qutebrowser\app.py", line 875, in eventFilter
File "scripts/dev\..\..\scripts\..\qutebrowser\app.py", line 835, in _handle_key_event
File "scripts/dev\..\..\scripts\..\qutebrowser\keyinput\modeman.py", line 337, in eventFilter
File "scripts/dev\..\..\scripts\..\qutebrowser\keyinput\modeman.py", line 168, in _eventFilter_keypress
File "scripts/dev\..\..\scripts\..\qutebrowser\keyinput\basekeyparser.py", line 311, in handle
File "scripts/dev\..\..\scripts\..\qutebrowser\keyinput\modeparsers.py", line 75, in _handle_single_key
File "scripts/dev\..\..\scripts\..\qutebrowser\keyinput\basekeyparser.py", line 200, in _handle_single_key
File "scripts/dev\..\..\scripts\..\qutebrowser\keyinput\keyparser.py", line 44, in execute
File "scripts/dev\..\..\scripts\..\qutebrowser\commands\runners.py", line 274, in run
File "scripts/dev\..\..\scripts\..\qutebrowser\commands\command.py", line 525, in run
File "scripts/dev\..\..\scripts\..\qutebrowser\browser\commands.py", line 1360, in download
File "scripts/dev\..\..\scripts\..\qutebrowser\browser\qtnetworkdownloads.py", line 386, in get
File "scripts/dev\..\..\scripts\..\qutebrowser\browser\qtnetworkdownloads.py", line 451, in get_request
File "scripts/dev\..\..\scripts\..\qutebrowser\browser\qtnetworkdownloads.py", line 467, in _fetch_request
File "scripts/dev\..\..\scripts\..\qutebrowser\browser\qtnetworkdownloads.py", line 509, in fetch
File "scripts/dev\..\..\scripts\..\qutebrowser\browser\downloads.py", line 160, in get_filename_question
File "scripts/dev\..\..\scripts\..\qutebrowser\browser\downloads.py", line 108, in _path_suggestion
File "scripts/dev\..\..\scripts\..\qutebrowser\browser\downloads.py", line 76, in download_dir
File "scripts/dev\..\..\scripts\..\qutebrowser\utils\standarddir.py", line 101, in download
File "scripts/dev\..\..\scripts\..\qutebrowser\utils\standarddir.py", line 193, in _create
File "c:\Python\64-bit\3.4\lib\os.py", line 237, in makedirs
PermissionError: [WinError 5] Access is denied: 'D:\\'

# Fixed code
def download_dir():
    """Get the download directory to use."""
    directory = config.val.downloads.location.directory
    remember_dir = config.val.downloads.location.remember

    if remember_dir and last_used_directory is not None:
        ddir = last_used_directory
    elif directory is None:
        ddir = standarddir.download()
    else:
        ddir = directory

    try:
        os.makedirs(ddir, exist_ok=True)
    except OSError as e:
        message.error("Failed to create download directory: {}".format(e))

    return ddir