Possible bug parsing file expert JSON response
alanhamlett opened this issue · 1 comments
alanhamlett commented
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:
- WakaTime API returning an invalid response
- WakaTime API returning a valid JSON response, but with an error message and wakatime-cli can't parse it
- WakaTime API returning a valid JSON response with empty data (when not yet availabe), and wakatime-cli can't parse it
gandarez commented
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>"}