From 4fca238780fc4294f244a58228f6fef2a0377faa Mon Sep 17 00:00:00 2001 From: Eugene Kalinin Date: Mon, 28 Sep 2026 23:03:17 +0300 Subject: [PATCH] fix(md2html): check curl exit status for network errors --- gh-md-toc | 3 ++- tests/tests.bats | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/gh-md-toc b/gh-md-toc index bce5271..fa203d9 100755 --- a/gh-md-toc +++ b/gh-md-toc @@ -83,10 +83,11 @@ gh_toc_md2html() { -H "Content-Type:text/plain" \ -H "$AUTHORIZATION" \ "$URL") + local curl_status=$? rm -f "${gh_file_md}~~" - if [ "$?" != "0" ]; then + if [ "$curl_status" != "0" ]; then echo "XXNetworkErrorXX" fi if [ "$(echo "${OUTPUT}" | awk '/API rate limit exceeded/')" != "" ]; then diff --git a/tests/tests.bats b/tests/tests.bats index f8b0443..b7b60b5 100755 --- a/tests/tests.bats +++ b/tests/tests.bats @@ -233,3 +233,12 @@ test_help() { assert_equal "${lines[8]}" "* [Title four is a particularly long title because of wrapping](#title-four-is-a-particularly-long-title-because-of-wrapping)" assert_equal "${lines[9]}" " * [This is a test for long titles](#this-is-a-test-for-long-titles)" } + +@test "Error for local file without network access" { + # route curl through a closed port to simulate a network failure + HTTPS_PROXY=http://127.0.0.1:9 run $BATS_TEST_DIRNAME/../gh-md-toc tests/test\ directory/test_plussign.md + assert_fail + + assert_equal "${lines[2]}" "Parsing local markdown file requires access to github API" + assert_equal "${lines[3]}" "Please make sure curl is installed and check your network connectivity" +}