Repository navigation
fix(toc): print the reason of a GitHub API error - #197
Merged
Merged
Conversation
Fixes #141. For an API error other than a network error, bad credentials or the rate limit, only the HTTP code was printed, and the reason that GitHub sends with it was dropped. A file larger than the API limit gave "Error: GitHub API request failed (HTTP 403)" without saying why. The message from the API answer is now printed as the next line: "This API renders Markdown text up to 400 KB in size. ...". When the answer has no message, the output is the same as before.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #141: for a GitHub API error other than a network error, bad credentials or the rate
limit, only the HTTP code was printed, and the reason that GitHub sends with it was
dropped. The #141 reporter thought it was a syntax error in the file; the file was larger
than the API limit.
Parsing local markdown file requires access to github APIError: GitHub API request failed (HTTP 403)exit 1
This API renders Markdown text up to 400 KB in size. The requested text is too large to render via the API.exit 1
About #141:
its file
0-IndiMail Wiki.mdis now 638679 bytes./markdown/raw) renders up to 409600 bytes: 409600 bytes render, 409601 bytesgive HTTP 403 with the message above. The limit counts bytes, not characters.
bytes after it, both above today's limit. What the limit was in 2023 cannot be checked
now.
gh-md-toc https://github.com/indimail/indimail-mta/wiki/0-IndiMail-Wiki,gives the TOC (160 entries), since GitHub renders the page itself.
--insertneeds alocal file below the limit.
Changes:
gh-md-toc(gh_toc_md2html): for other API errors, themessagefield of the JSONanswer is taken with
awkand passed in the error marker (XXApiErrorXX <code> <message>). The branches for network errors, bad credentials and the rate limit are notchanged.
gh-md-toc(gh_toc_check_api_error): the two lines are printed as before, and themessage as the next line when there is one. Without a message the output is the same
as before. With
--stdoutthe lines go to stderr, as before.tests/tests.bats: a new test (#141) with a 1048576-byte file in$BATS_TEST_TMPDIR,well above the limit, so it does not depend on the exact number; it checks only
too largein the message, since the text is GitHub's.openspec: thefix-api-error-messagechange (proposal, design, specs, tasks), notarchived yet.
Not included: a TOC for files larger than the API limit (splitting a file would mean
parsing markdown, and anchors of repeated headings would differ from GitHub); a size
check before the API call (the limit would be a number in the script).
Testing
(macOS, BSD awk 20200816).
ubuntu:24.04with mawk.--stdouton a 1 MiB file with markers print the three lines(on stdout and on stderr) with exit code 1.
make lintpasses.