Commit caf32bf
Kai Liu
fix(discord): forward DiscordAPIError code through resolveTextChannel wrapper
Addresses Codex P2 review on PR #211. resolveTextChannel() catches each
client.channels.fetch() failure and then rethrows a generic
Error("Discord channel ... is not text-based or inaccessible") with no
`code` attached. That generic error reaches isPermanentChannelError(),
which checks for numeric DiscordAPIErrorcode (10003 Unknown Channel /
50001 Missing Access / etc.) and falls through to false — so a Discord
cron job whose bot has been removed from the target channel stays
enabled and keeps firing every tick, exactly the noise pattern this PR
exists to fix.
Capture every Discord API code from each fetch attempt, pick a permanent
one (10003 / 50001 / 50013 / 50007) when available, and attach it to the
thrown wrapper as `code` (with the full list on `discordErrorCodes`
for diagnostics). The wrapper's message is unchanged so callers that
match on the string still work.
Add a permanent-error.test.ts case asserting the wrapper Error with a
forwarded code is classified as permanent.
bun test: 419 pass, 1 skip, 0 fail.1 parent 46fe172 commit caf32bf
2 files changed
Lines changed: 42 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
116 | 116 | | |
117 | 117 | | |
118 | 118 | | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
119 | 133 | | |
120 | 134 | | |
121 | 135 | | |
| |||
126 | 140 | | |
127 | 141 | | |
128 | 142 | | |
| 143 | + | |
129 | 144 | | |
130 | 145 | | |
131 | 146 | | |
| |||
141 | 156 | | |
142 | 157 | | |
143 | 158 | | |
| 159 | + | |
144 | 160 | | |
145 | 161 | | |
146 | 162 | | |
| |||
154 | 170 | | |
155 | 171 | | |
156 | 172 | | |
157 | | - | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
158 | 187 | | |
159 | 188 | | |
160 | 189 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
42 | 54 | | |
43 | 55 | | |
44 | 56 | | |
| |||
0 commit comments