Skip to content

Commit 84c3c45

Browse files
authored
Better wasm http timeout error message (#190)
1 parent 36b094a commit 84c3c45

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

‎src/wasm/stream.cpp‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
# include "stream.hpp"
44

5+
# include <cstdlib>
56
# include <regex>
67
# include <sstream>
8+
# include <string>
79

810
# include <emscripten.h>
911

@@ -283,12 +285,16 @@ static void convert_js_to_git_error(wasm_http_stream* stream)
283285
}
284286
else if (std::string_view(error_str).starts_with("TimeoutError:"))
285287
{
288+
auto env_var = std::getenv(WASM_HTTP_TRANSPORT_TIMEOUT_NAME.data());
289+
std::string value = env_var != nullptr ? env_var
290+
: std::to_string(WASM_HTTP_TRANSPORT_TIMEOUT_DEFAULT_S);
286291
git_error_set(
287292
GIT_ERROR_HTTP,
288-
"network request timed out connecting to %s. You can set a longer timeout in seconds using the environment variable %s, the default value is %u seconds.",
293+
"network request timed out connecting to %s. You can set a longer timeout in seconds using the environment variable %s, the %s value is %s seconds.",
289294
stream->m_unconverted_url.c_str(),
290295
WASM_HTTP_TRANSPORT_TIMEOUT_NAME.data(),
291-
WASM_HTTP_TRANSPORT_TIMEOUT_DEFAULT_S
296+
env_var != nullptr ? "current" : "default",
297+
value.c_str()
292298
);
293299
}
294300
else

‎test/test_clone.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ def test_clone_timeout(git2cpp_path, tmp_path, run_in_tmp_path):
180180
"set a longer timeout in seconds using the environment variable GIT_HTTP_TIMEOUT"
181181
in p_clone.stderr
182182
)
183+
assert "the current value is 0.001 seconds" in p_clone.stderr
183184

184185
# Set more reasonable timeout.
185186
subprocess.run(["export", "GIT_HTTP_TIMEOUT=10"], check=True)

0 commit comments

Comments
 (0)