Skip to content

fix(rest): return what the endpoints actually answer with - #18

Merged
mikield merged 1 commit into
masterfrom
fix/return-shapes
Sep 2, 2026
Merged

mikield merged 1 commit into
masterfrom
fix/return-shapes

Conversation

@mikield

@mikield mikield commented Sep 2, 2026

Copy link
Copy Markdown
Member

Two problems, found by auditing every @return PromiseInterface<...> against the mapper used beside it.

Three methods that have never worked

GuildScheduledEvent::get(), create() and modify() call mapArrayPromise(). Discord answers each of them with one event, and DataMapper::mapArray() declares its parameter as array — so a stdClass reaches it and the call dies on a TypeError before returning anything.

There was no test file for the class at all, which is how three of its six methods came to have never worked. There is one now, covering all six.

This is the third instance of exactly this bug in this repo (createChannel, the archived-thread listings, now these), and each time the tell was the same: an untested method with mapArrayPromise on a singular endpoint.

Eleven annotations that disagreed with the code

Nothing breaks at runtime, but every consumer's static analysis is told the wrong shape — which is how this was noticed. A bot reading getBan()->reason was told it was accessing a property on array<GuildBan>:

Documented as a list, returns one Documented as one, returns a list
Guild::getBan Guild::getVoiceRegions
Webhook::get Guild::getInvites
Webhook::getWithToken Guild::getIntegrations
Webhook::modify Channel::getChannelInvites
Webhook::modifyWithToken GuildTemplate::list
ApplicationRoleConnectionMetadata::getRecords
ApplicationRoleConnectionMetadata::updateRecords

Found while building a ban-appeal flow that reads a ban's reason back off getBan().

🤖 Generated with Claude Code

GuildScheduledEvent::get(), create() and modify() mapped their answer as
an array. Discord answers each with one event, and mapArray() declares
its parameter as array, so every call died on a TypeError before it
returned anything. There was no test file for the class at all, which is
how three of its six methods came to have never worked.

Eleven more methods had a @return that disagreed with the mapper beside
it — getBan and four Webhook methods documented as lists while returning
one object, and getVoiceRegions, getInvites, getIntegrations,
getChannelInvites, GuildTemplate::list and the two role connection
metadata methods documented as one while returning lists. Nothing broke
at runtime, but every caller's static analysis was told the wrong shape,
which is how this was noticed: a bot reading getBan()->reason was told it
was reading a property on an array.
@mikield
mikield merged commit 77e56e0 into master Sep 2, 2026
4 checks passed
@mikield
mikield deleted the fix/return-shapes branch September 2, 2026 15:35
github-actions Bot pushed a commit that referenced this pull request Sep 2, 2026
## [1.3.4](v1.3.3...v1.3.4) (2026-09-02)

### Bug Fixes

* **rest:** return what the endpoints actually answer with ([#18](#18)) ([77e56e0](77e56e0))
@github-actions

github-actions Bot commented Sep 2, 2026

Copy link
Copy Markdown

🎉 This PR is included in version 1.3.4 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant