Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cannot unmarshal array into Go value of type models.Heartbeat #688

Closed
alanhamlett opened this issue Oct 8, 2024 · 7 comments
Closed

cannot unmarshal array into Go value of type models.Heartbeat #688

alanhamlett opened this issue Oct 8, 2024 · 7 comments
Assignees
Labels
bug Something isn't working effort:3 prio a

Comments

@alanhamlett
Copy link
Contributor

I'm seeing a 400 error response from https://wakapi.dev/api/compat/wakatime/v1/users/current/heartbeats.bulk:

json: cannot unmarshal array into Go value of type models.Heartbeat

When sending JSON payload:

[
  {
    "branch":"<<LAST_BRANCH>>",
    "entity":"https://wakapi.dev",
    "id":"f3647f89-e255-4dd1-8fcd-e20ba8f1709b",
    "project":"<<LAST_PROJECT>>",
    "time":"1728422364.044",
    "type":"domain",
    "userAgent":"Chrome/129.0.0.0 mac_x86-64 chrome-wakatime/4.0.6"
  }
]

Might be from time being a string instead of number. The WakaTime API accepts both types, but we prefer string to avoid any floating point accuracy errors.

Or, it could be the id or userAgent attributes, which might not be known by wakapi.

Lastly, it could be "type": "domain", but I assume wakapi should support that because it's been used by the browser extension for many years already.

System information

  • Wakapi version: cloud
  • Operating system: Chrome browser extension
@muety
Copy link
Owner

muety commented Oct 9, 2024

It's both, the id field and time field being strings, while Wakapi expects numbers for both. Relates to #682. Not entirely sure how to best go about this. Generally, having to support multiple data types (in case of time) for the same field name is a bit painful imo and doesn't go very well with statically typed code. I'll probably have to introduce separate view models and add a bunch of hacks here and there. Will have a look soon.

@muety
Copy link
Owner

muety commented Oct 13, 2024

@alanhamlett Can you give a few hints about what has changed on the plugin's end to cause these failures? Did the payload of heartbeats sent to the API change? Can you point me to the relevant commits in the plugin's codebase, please?

@muety
Copy link
Owner

muety commented Oct 13, 2024

To be honest, rather than putting long-winded hacks in place on Wakapi's heartbeats endpoint, I'd prefer to make the plugin follow the payload format specified in the docs, where time is a float and id is not included. What do you think? I can do a PR if desired.

@alanhamlett
Copy link
Contributor Author

Sure, I'll fix that in the browser extension.

@alanhamlett
Copy link
Contributor Author

@muety
Copy link
Owner

muety commented Oct 14, 2024

Thanks! 👍 Pushed a fix to Wakapi in the meanwhile well. Actually, sending time as strings has been fine and Wakapi will ignore incoming id in the latest version.

@alanhamlett
Copy link
Contributor Author

Ok, I'll revert my browser-wakatime change then. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working effort:3 prio a
Projects
None yet
Development

No branches or pull requests

2 participants