Repository navigation
fix(cursor): accept numeric strings in spendLimitUsage - #155
Itstommy10 wants to merge 1 commit into
Conversation
Cursor returns some spendLimitUsage fields as strings (e.g. pooledLimit "0" on free accounts), which made the whole usage response fail to decode with "cannot unmarshal string into ... pooledLimit of type int". Decode the integer fields from numbers, numeric strings, empty strings or null. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
|
Thanks a lot for digging into this and sending a fix, @Itstommy10, and for checking it against a real Free account. That confirmation is really useful. The same issue was reported as #151, and the fix landed on main in #153 and ships in v2.14.14. It adds string-tolerant decoders for every numeric field in the Cursor responses, not just spendLimitUsage, and also handles "", null, decimals (rounded), and NaN, Inf and overflow. A field that can't be read now drops only the quota it defines, with a warning, instead of being stored as 0. Main also has a regression test for a Free account with a string pooledLimit. Because main already defines UnmarshalJSON on CursorSpendLimitUsage and the fields are no longer plain int, this branch would not compile after a rebase, so I am closing it as superseded. If you still see a Cursor decode error on v2.14.14, please open an issue with the log line and a redacted payload and we will take a look. Thanks again! |
Summary
Cursor's usage endpoint returns some
spendLimitUsagefields as strings instead of numbers (seen on a Free account:"pooledLimit":"0"). BecauseCursorSpendLimitUsagedeclares them asint, decoding the whole usage response failed and Cursor polling never stored data:This adds a custom
UnmarshalJSONforCursorSpendLimitUsagethat accepts the integer fields as JSON numbers, numeric strings, empty strings ornull(empty/null/non-numeric decode as 0). The struct fields and all call sites stayint, so nothing else changes.Test plan
go vet ./internal/api/andgo test ./internal/api/Cursor poll complete account_type=individual plan_name=Free quota_count=2)