Skip to content

Commit

Permalink
Merge pull request #231 from Predelnik/network
Browse files Browse the repository at this point in the history
Process more errors during dictionary downlaod
  • Loading branch information
Predelnik authored Oct 14, 2020
2 parents f98d7cf + 5dd0df7 commit 3c2aa04
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
1 change: 1 addition & 0 deletions Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ v1.4.18
* Ignore words in URLs in newer version of Notepad++ correctly (#67)
* Fix broken rechecking on scrolling after quick edit after scrolling has been done (#222)
* New words not being rechecked in case of zooming out (#225)
* Process more errors during dictionary downloading

v1.4.17
* Fix interaction with some other plugins (e.g. PythonScript) (#219)
Expand Down
1 change: 1 addition & 0 deletions deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ def add_version_commit():
author = Signature(config['user.name'], config['user.email'])

def add_version_tag ():
repo = Repository (script_dir)
repo.create_tag('v{}'.format (ver_str), repo.revparse_single('HEAD').id, GIT_OBJ_COMMIT, author, 'v{}'.format (ver_str))

new_ver_is_added = False
Expand Down
1 change: 1 addition & 0 deletions src/FileListProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ enum class FileListProviderDownloadErrorType
none,
canceled,
file_is_not_writeable,
was_not_able_to_download,
};

class FileListProvider
Expand Down
18 changes: 12 additions & 6 deletions src/GithubFileListProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void GitHubFileListProvider::update_file_list() {
std::wstring proxy_string;
if (m_settings.data.use_proxy && m_settings.data.proxy_type == ProxyType::web_proxy)
proxy_string = m_settings.data.proxy_host_name + L":" + std::to_wstring(m_settings.data.proxy_port);
using task_result_t = std::variant<std::monostate, std::vector<FileDescription>, Win32Exception>;
using task_result_t = std::variant<std::monostate, std::vector<FileDescription>, std::string /*error*/>;
// TODO: possibly separate settings required for proxy connection to a struct to pass them instead of whole settings
auto task = [root_path = m_root_path, proxy_string, default_timeout, settings_data = m_settings.data](Concurrency::cancellation_token token) -> task_result_t {
try {
Expand All @@ -60,8 +60,8 @@ void GitHubFileListProvider::update_file_list() {
auto reset_secs = core_limit_data["reset"].get<time_t>();
std::wstringstream wss;
wss << std::put_time(std::localtime(&reset_secs), L"%H:%M");
return Win32Exception(to_string (wstring_printf(rc_str(IDS_GITHUB_API_RATE_LIMIT_EXCEEDED_PD_PS).c_str(), core_limit_data["limit"].get<int>(),
wss.str ().c_str ())));
return to_string (wstring_printf(rc_str(IDS_GITHUB_API_RATE_LIMIT_EXCEEDED_PD_PS).c_str(), core_limit_data["limit"].get<int>(),
wss.str ().c_str ()));
}
nlohmann::json nodes;
std::wstring download_url;
Expand Down Expand Up @@ -90,13 +90,13 @@ void GitHubFileListProvider::update_file_list() {
download_url + utf8_to_wstring(node["path"].get<std::string>().c_str())});
}
return result;
} catch (const Win32Exception &exception) {
return exception;
} catch (const std::exception &exception) {
return exception.what ();
}
};
m_get_file_list_task.do_deferred(task, [this](task_result_t &&result) {
std::visit(overload([](std::monostate) {}, [this](std::vector<FileDescription> &&list) { file_list_received(std::move(list)); },
[this](Win32Exception &&e) { error_happened(e.what()); }),
[this](std::string &&str) { error_happened(str); }),
std::move(result));
});
}
Expand Down Expand Up @@ -170,6 +170,7 @@ void GitHubFileListProvider::download_dictionary(const std::wstring &aff_filepat
std::shared_ptr<ProgressData> progress_data) {
m_download_file_task.do_deferred(
[=, settings_data = m_settings.data](Concurrency::cancellation_token token) {
try {
std::vector<std::wstring> downloaded_filenames;
auto ret = download_dictionary_impl (token, aff_filepath, target_path, progress_data, downloaded_filenames, settings_data);
if (ret != FileListProviderDownloadErrorType::none)
Expand All @@ -178,6 +179,11 @@ void GitHubFileListProvider::download_dictionary(const std::wstring &aff_filepat
WinApi::delete_file(file_name.c_str());
}
return ret;
}
catch (const std::exception &) {
// TODO: display exception error in ui
return FileListProviderDownloadErrorType::was_not_able_to_download;
}
},
[this](FileListProviderDownloadErrorType error) { file_downloaded(error); });
}
Expand Down

0 comments on commit 3c2aa04

Please sign in to comment.