docs: document the exported API, and fix five bugs found writing it#2
Merged
Conversation
The package carried 35 Russian comments and no doc comments on its exported identifiers, so pkg.go.dev rendered a bare list of signatures. Translate the Russian to English and give every exported identifier a doc comment in godoc form. Add doc.go with a package overview covering the guest-session requirement, the Error-as-struct convention, and CloudFront blocking. The comments record what the signatures cannot: that UpdateCSRF must run first and that its token expires, that Error is a struct and so is never nil, that Thread is one comment rather than a thread, and that GetComments' page parameter costs one request per page. Comments only; the struct field realignment is gofmt's, from doc comments splitting alignment groups. Refs #1
Writing doc comments for the exported API surfaced behavior too alarming
to document and leave alone. A library should never terminate the process
that imports it.
Crashes:
- GetComments panicked on a comment with an empty body: the shape check
read m[0] and m[len(m)-1] with no length check.
- Group.Favourites and Group.Gallery indexed their variadic folderid
without checking len, so omitting it — which the signature invites —
panicked. Omitting it now means 0.
- AEmedia and PerformSearch called log.Fatalln on a bad argument rune,
terminating the caller. Both now return an error, which their
signatures already allowed for.
Draft.js flattening, in the same code both callers share:
- The block loop assigned rather than accumulated, so every block but the
last was dropped and a multi-paragraph body came back as its closing
line alone. Blocks are block-level elements, so join them with newlines.
- GetDeviation guarded on txt[1] == '{', the second character of a body
that opens with {"blocks". It never fired, so descriptions were handed
back as raw Draft.js JSON. It now shares flattenComment with
GetComments rather than keeping its own copy.
Both flattening fixes change output for existing callers.
Refs #1
ccleberg
force-pushed
the
docs/translate-and-expand-comments
branch
from
July 15, 2026 19:49
2f7703d to
3dad0ea
Compare
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.
Closes #1.
Documentation
The package carried 35 Russian comments and no doc comments on its exported
identifiers, so pkg.go.dev rendered a bare list of signatures. Every exported
identifier now has a godoc-form comment, and
doc.goadds a package overviewcovering the guest-session requirement, the
Error-as-struct convention, andCloudFront blocking.
The comments record what the signatures cannot: that
UpdateCSRFmust run firstand that its token expires, that
Erroris a struct and so is never nil, thatThreadis one comment rather than a thread, and thatGetComments'pageparameter costs one request per page.
On the issue's third item — a dedicated docs site looks unnecessary. pkg.go.dev
already indexes this module (v0.3.1) and will pick these comments up on the next
tag, with no build step or hosting to maintain. The README is the gap worth
filling instead, since it lists endpoints but shows no usage; the package doc now
has an example that could be mirrored there.
Fixes
Documenting the API meant writing down behavior that was too alarming to leave
alone. A library should never kill the process that imports it:
GetCommentspanicked on a comment with an empty body (m[0]unguarded).Group.FavouritesandGroup.Gallerypanicked whenfolderidwas omitted,which their variadic signatures invite. Omitting it now means 0.
AEmediaandPerformSearchcalledlog.Fatallnon a bad argument,terminating the caller. Both now return an error, which their signatures
already allowed for.
Two more in the Draft.js flattening, which
GetCommentsandGetDeviationnowshare rather than each keeping a copy of:
back as its closing line alone.
GetDeviationguarded ontxt[1] == '{'— the second character of a body thatopens with
{"blocks". It never fired, so descriptions were returned as rawDraft.js JSON rather than text.
The docs and the fixes are one PR because the doc comments describe the fixed
behavior; splitting them would mean writing those comments twice.
Behavior changes, worth a careful look
Both flattening fixes change output for existing callers.
CommentandDescriptionwill return text that is longer (every paragraph, not just thelast) and, for descriptions, no longer raw JSON. This is what the code always
intended, but it is a real change and not merely a crash fix.
The
GetDeviationfix is verified by reasoning about the guard rather thanagainst the live API, since
GetDeviationhas no seam to inject a responsethrough — worth a second opinion from someone who knows what DeviantArt actually
returns.
flattenCommentitself is covered directly by tests.Checks
go build,go vet,go test(16 tests), andgolangci-lint runall pass; noCyrillic remains in the tree.
Not addressed
Left alone deliberately, as out of scope and breaking:
Thread.Desctiptionismisspelled and
Post.ParsedCommentsappears to be dead — nothing populateseither, but renaming an exported field breaks the API and I could not confirm
from the code alone whether DeviantArt ever sends them.