wakatime / wakatime-cli

Command line interface used by all WakaTime text editor plugins
https://wakatime.com/plugins
BSD 3-Clause "New" or "Revised" License
264 stars 41 forks source link

Possible bug parsing file expert JSON response #919

Closed alanhamlett closed 11 months ago

alanhamlett commented 11 months ago

I’m seeing this error from wakatime-cli:

{"caller":"pkg/heartbeat/sanitize.go:30","func":"fileexperts.initHandleOptions","level":"debug","message":"execute heartbeat sanitization","now":"2023-08-25T13:10:21Z","os/arch":"linux/amd64","version":"v1.76.0"}
{"caller":"pkg/api/fileexperts.go:36","func":"api.(*Client)","level":"debug","message":"fileexpert: {\"entity\":\"/workspaces/codespaces-blank/test.txt\",\"project\":\"\",\"project_root_count\":3}","now":"2023-08-25T13:10:21Z","os/arch":"linux/amd64","version":"v1.76.0"}
{"caller":"cmd/run.go:310","func":"cmd.runCmd","level":"error","message":"failed to run command: file experts fetch failed: bad request: bad request at \"https://api.wakatime.com/api/v1/users/current/file_experts\"","now":"2023-08-25T13:10:22Z","os/arch":"linux/amd64","version":"v1.76.0"}

This could be:

gandarez commented 11 months ago

The error happens when project couldn't be auto-detected. I'll create a validation to not call file experts endpoint when entity, project or project root count is empty.

{"caller":"pkg/api/fileexperts.go:36","func":"api.(*Client)","level":"debug","message":"fileexpert: {\"entity\":\"/Users/gandarez/.wakatime/wakatime.log\",\"project\":\"\",\"project_root_count\":4}","now":"2023-08-26T17:03:09-03:00","os/arch":"darwin/arm64","version":"<local-build>"}
{"caller":"pkg/api/fileexperts.go:64","func":"api.(*Client)","level":"debug","message":"bad request at \"https://api.wakatime.com/api/v1/users/current/file_experts\". body: \"{\\\"errors\\\": {\\\"project\\\": [\\\"This field is required.\\\"]}}\"","now":"2023-08-26T17:03:10-03:00","os/arch":"darwin/arm64","version":"<local-build>"}