Repository navigation
Handle bad credentials - #151
Conversation
Also fixes a bug where XXNetworkErrorXX wouldn’t be caught due to value of $? changing after rm call.
ekalinin
left a comment
There was a problem hiding this comment.
Thanks for the PR. A few things need to be fixed before it can be merged:
-
Conflicts with master. The PR is based on 0.10.0. The
$?fix is already on master ascurl_status(#172), and the whole-file shfmt reformat touches most of the functions changed since then (--depth,--numbered, lint fixes). Please rebase onto current master and keep only the bad-credentials change, without the reformat. -
--insertwipes the TOC on GNU sed. The shfmt commit changed the probe toif ! sed --version || true >/dev/null 2>&1, which is always true, so GNU sed also getssed -i "". On Linux the old TOC is deleted, the new one is not inserted, and the tool still prints!! TOC was added. With--no-backupthe backup is removed too. The existing tests don't catch it because they don't check the file after--insert. -
False "bad credentials" error.
awk '/Bad credentials/'runs over the rendered HTML of the user's document, so any markdown that mentions "Bad credentials" fails with exit 1 even with a valid token. Checking the HTTP status (401) instead of the response body would avoid this. -
No tests. Please add a test for the bad-credentials case, e.g.
GH_TOC_TOKEN=invalid gh-md-toc README.mdexpecting exit 1 and the error message.
The blanket reformat conflicts with most functions changed upstream and broke the GNU sed probe (sed -i "" on Linux). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Nj7TK1eX93Wj8qZBBkbvdR
Resolves conflicts with upstream (the curl exit-status fix already landed there as curl_status in ekalinin#172) and addresses review feedback: - Detect bad credentials via HTTP 401 instead of grepping the rendered HTML, so markdown that mentions "Bad credentials" no longer fails. - Only treat "API rate limit exceeded" as a rate limit on a non-200 response, fixing the same false positive. - Report other non-200 API responses as an error instead of producing an empty TOC. - Point the bad-credentials hint at whichever token source was used (GH_TOC_TOKEN or token.txt). - Add tests for an invalid token and for docs mentioning API error text. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Nj7TK1eX93Wj8qZBBkbvdR
|
Thanks for the review. I've pushed changes for all four points:
The bad-credentials message now says which token source was used ( |
ekalinin
left a comment
There was a problem hiding this comment.
Thanks for the update. All four points from the previous review are fixed. One thing is still missing before this can be merged:
- stdin input still fails silently. When reading from stdin (
gh-md-toc -, line 447), the output ofgh_toc_md2htmlgoes straight togh_toc_grab, so the new error markers are never checked there.printf '# A\n' | GH_TOC_TOKEN=bad ./gh-md-toc -still prints an empty TOC and exits 0, while the same input from a file now exits 1 with the bad-credentials error. Please handleXXBadCredentialsXXandXXApiErrorXXfor stdin too, and add a test for it.
`gh-md-toc -` piped gh_toc_md2html straight into gh_toc_grab, so bad credentials, rate limits, other API errors and network failures all printed an empty TOC and exited 0. Move the marker checks into gh_toc_check_api_error and call it from both the file and stdin paths. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Nj7TK1eX93Wj8qZBBkbvdR
|
Thanks! Fixed in 7ce7e0d. The error checks are now in one function, I added two stdin tests: one with an invalid token and one with no network access. |
|
Thanks! |
Also: