wakatime / vscode-wakatime

Visual Studio Code plugin for automatic time tracking and metrics generated from your programming activity.
https://wakatime.com/vs-code
BSD 3-Clause "New" or "Revised" License
1.23k stars 137 forks source link

Using wrong wakatime-cli binary file name on Linux arm64 #216

Closed simonSlamka closed 3 years ago

simonSlamka commented 3 years ago

Hello,

I'm experiencing unexpected behavior in my vscode with the wakatime extension. I have confirmed that my API key is correct. The log in the home directory is empty.

Repro is to just install the extension, input your API key and get it to attempt to sync.

VSCode: image

VSCode console says the following:

[WakaTime][ERROR] /home/simtoon/.wakatime/wakatime-cli/wakatime-cli: 1: /home/simtoon/.wakatime/wakatime-cli/wakatime-cli: �7@8@@@@@@��@@@@�u�u: not found/home/simtoon/.wakatime/wakatime-cli/wakatime-cli: 1: /home/simtoon/.wakatime/wakatime-cli/wakatime-cli: ��: not found/home/simtoon/.wakatime/wakatime-cli/wakatime-cli: 1: /home/simtoon/.wakatime/wakatime-cli/wakatime-cli: ��@@DDP�td�e�e@�e@ttQ�td/lib64/ld-linux-x86-64.so.2GNU: not found/home/simtoon/.wakatime/wakatime-cli/wakatime-cli: 1: /home/simtoon/.wakatime/wakatime-cli/wakatime-cli: +Pz: not found/home/simtoon/.wakatime/wakatime-cli/wakatime-cli: 1: /home/simtoon/.wakatime/wakatime-cli/wakatime-cli: cannot create E@@�u�uXHzlibdl.so.2_ITM_deregisterTMCloneTable__gmon_start___Jv_RegisterClasses_ITM_registerTMCloneTabledlsymdlopendlerrorlibz.so.1inflateinflateInit_inflateEndlibc.so.6__stpcpy_chk__xpg_basenamemkdtempfflushstrcpyfchmodreaddirsetlocalefopenwcsncpystrncmp__strdupperrorclosedirftellsignalstrncpymbstowcsforkunlinkmkdirstdingetpidkillstrtokfeofcallocstrlenmemsetdirnamermdirfseekclearerrunsetenv__fprintf_chkstdoutstrnlenfclose__vsnprintf_chkmallocstrcatrealpathraise__strncpy_chknl_langinfoopendirgetenvstderr__snprintf_chk__strncat_chkexecvpstrncat__realpath_chkfilenofwritefreadwaitpidstrchr__vfprintf_chk__strcpy_chk__xstat__strcat_chksetbufstrcmp__libc_start_mainferrorstpcpyfreeGLIBC_2.2.5GLIBC_2.3GLIBC_2.4GLIBC_2.3.4: File name too long/home/simtoon/.wakatime/wakatime-cli/wakatime-cli: 1: /home/simtoon/.wakatime/wakatime-cli/wakatime-cli: ELF: not found/home/simtoon/.wakatime/wakatime-cli/wakatime-cli: 1: /home/simtoon/.wakatime/wakatime-cli/wakatime-cli: Syntax error: word unexpected (expecting ")")

Furthermore, it reports the following:

[WakaTime][ERROR] Error: Command failed: /home/simtoon/.wakatime/wakatime-cli/wakatime-cli --entity /home/simtoon/terminalInsanityCLI/terminalInsanityCONSOLE/zshVerify --plugin "vscode/1.59.0-insider vscode-wakatime/14.0.0" --alternate-project terminalInsanityCLI/home/simtoon/.wakatime/wakatime-cli/wakatime-cli: 1: /home/simtoon/.wakatime/wakatime-cli/wakatime-cli: �7@8@@@@@@��@@@@�u�u: not found/home/simtoon/.wakatime/wakatime-cli/wakatime-cli: 1: /home/simtoon/.wakatime/wakatime-cli/wakatime-cli: ��: not found/home/simtoon/.wakatime/wakatime-cli/wakatime-cli: 1: /home/simtoon/.wakatime/wakatime-cli/wakatime-cli: ��@@DDP�td�e�e@�e@ttQ�td/lib64/ld-linux-x86-64.so.2GNU: not found/home/simtoon/.wakatime/wakatime-cli/wakatime-cli: 1: /home/simtoon/.wakatime/wakatime-cli/wakatime-cli: +Pz: not found/home/simtoon/.wakatime/wakatime-cli/wakatime-cli: 1: /home/simtoon/.wakatime/wakatime-cli/wakatime-cli: cannot create E@@�u�uXHzlibdl.so.2_ITM_deregisterTMCloneTable__gmon_start___Jv_RegisterClasses_ITM_registerTMCloneTabledlsymdlopendlerrorlibz.so.1inflateinflateInit_inflateEndlibc.so.6__stpcpy_chk__xpg_basenamemkdtempfflushstrcpyfchmodreaddirsetlocalefopenwcsncpystrncmp__strdupperrorclosedirftellsignalstrncpymbstowcsforkunlinkmkdirstdingetpidkillstrtokfeofcallocstrlenmemsetdirnamermdirfseekclearerrunsetenv__fprintf_chkstdoutstrnlenfclose__vsnprintf_chkmallocstrcatrealpathraise__strncpy_chknl_langinfoopendirgetenvstderr__snprintf_chk__strncat_chkexecvpstrncat__realpath_chkfilenofwritefreadwaitpidstrchr__vfprintf_chk__strcpy_chk__xstat__strcat_chksetbufstrcmp__libc_start_mainferrorstpcpyfreeGLIBC_2.2.5GLIBC_2.3GLIBC_2.4GLIBC_2.3.4: File name too long/home/simtoon/.wakatime/wakatime-cli/wakatime-cli: 1: /home/simtoon/.wakatime/wakatime-cli/wakatime-cli: ELF: not found/home/simtoon/.wakatime/wakatime-cli/wakatime-cli: 1: /home/simtoon/.wakatime/wakatime-cli/wakatime-cli: Syntax error: word unexpected (expecting ")")

At the end, it says this:

[WakaTime][ERROR] Unknown Error (2); Check your /home/simtoon/.wakatime.log file for more details (at t.Logger.log (/home/simtoon/.vscode-insiders/extensions/wakatime.vscode-wakatime-14.0.0/dist/extension.js:2:723869))

As I said, the log mentioned above is empty.

simonSlamka commented 3 years ago

I have identified an issue with the aforementioned build of VSCode: by default, when installing the plugin, it installs a x86_64 one instead of arm64, even when on arm64. So VSCode probably mistakenly pulls the intel/amd one. Maybe it has something to do with the insiders build, though.

simonSlamka commented 3 years ago

It took a minute, but I came up with a sneaky workaround for this issue by forcing the arm64 executable by locking out the extension from updating. On each launch, it updates itself and the CLI, right? well, as I mentioned here:

... So VSCode probably mistakenly pulls the intel/amd one. Maybe it has something to do with the insiders build, though ...

It downloads the x86_64 one for some reason, even when on arm64. Downloading the arm64 one manually works, but gets overwritten when the plugin updates the CLI. So I prevented VSCode from accessing the binary (I chowned it to root), so it couldn't be overwritten. Now it's working and sending out heartbeats correctly. Please include a check into the plugin that verifies the current arch. For example, gcc is capable of that.

Thanks

alanhamlett commented 3 years ago

The wakatime plugin uses os.arch() to detect amd64 or arm64. Maybe os.arch() is returning an unexpected string value, since the wakatime plugin expects the returned string to contain amd when arch is amd64.

alanhamlett commented 3 years ago

Could you please:

  1. clone this repo
  2. edit vscode-wakatime/src/dependencies.ts and add console.log(os.arch()); to line 437
  3. run npm install && npm run compile from inside the root folder of this repo
  4. run rm ~/.vscode/extensions/wakatime.vscode-wakatime-14.0.0/dist/extension.js
  5. run ln -s ./dist/extension.js ~/.vscode/extensions/wakatime.vscode-wakatime-14.0.0/dist/extension.js from the root folder of this repo
  6. Press ctrl + r inside the VS code dev console (Help -> Toggle Developer Tools) or just restart vscode
  7. Look in the vscode dev console window for the output from os.arch() and paste that output here
simonSlamka commented 3 years ago

Could you please:

1. clone this repo

2. edit `vscode-wakatime/src/dependencies.ts` and add `console.log(os.arch());` to line `437`

3. run `npm install && npm run compile` from inside the root folder of this repo

4. run `rm ~/.vscode/extensions/wakatime.vscode-wakatime-14.0.0/dist/extension.js`

5. run `ln -s ./dist/extension.js ~/.vscode/extensions/wakatime.vscode-wakatime-14.0.0/dist/extension.js` from the root folder of this repo

6. Press `ctrl + r` inside the VS code dev console (Help -> Toggle Developer Tools) or just restart vscode

7. Look in the vscode dev console window for the output from `os.arch()` and paste that output here

On it.

simonSlamka commented 3 years ago
ln -s ./dist/extension.js ~/.vscode/extensions/wakatime.vscode-wakatime-14.0.0/dist/extension.js

symlinking didn't work, I had 'missing modules', however, copying worked.


Hmm, it outputs arm64. So the issue is elsewhere ...

simonSlamka commented 3 years ago

Why are you doing this?

https://github.com/wakatime/vscode-wakatime/blob/7ab65d76830670ebfd112db6c3ff2ad6e8345164/src/dependencies.ts#L113-L125

simonSlamka commented 3 years ago

The problem seems to be that the latest arm64 binary is not being detected as the latest when polling the version value from GitHub. Still, that doesn't explain how we got from arm64 to x86_64. os.arch() is indeed working correctly.

alanhamlett commented 3 years ago

Why are you doing this?

https://github.com/wakatime/vscode-wakatime/blob/7ab65d76830670ebfd112db6c3ff2ad6e8345164/src/dependencies.ts#L113-L125

We currently have two wakatime-cli implementations. The new Go one and the legacy Python one. We download both so we can test the new Go one but fallback to the more stable Python one if the Go one errors.

alanhamlett commented 3 years ago

Can you turn on debug mode in the wakatime plugin settings, then open the vscode dev console and reload. Then paste the logs here?

simonSlamka commented 3 years ago

@alanhamlett Look at the original post, the three code blocks there are the erroneous output.

Thanks

simonSlamka commented 3 years ago

Here is the full output:

[Extension Host] [WakaTime][DEBUG] Initializing WakaTime v14.0.0
console.ts:137 [Extension Host] [WakaTime][DEBUG] Downloading legacy python wakatime-cli...
console.ts:137 [Extension Host] [WakaTime][DEBUG] Extracting wakatime-cli into "/home/parallels/.wakatime"...
console.ts:137 [Extension Host] [WakaTime][DEBUG] Finished extracting wakatime-cli.
console.ts:137 [Extension Host] [WakaTime][DEBUG] Chmod 755 wakatime-cli...
2console.ts:137 [Extension Host] arm64
console.ts:137 [Extension Host] [WakaTime][DEBUG] GitHub API Response 304
console.ts:137 [Extension Host] [WakaTime][DEBUG] Downloading wakatime-cli v1.18.9...
console.ts:137 [Extension Host] arm64
console.ts:137 [Extension Host] [WakaTime][DEBUG] Extracting wakatime-cli into "/home/parallels/.wakatime"...
2console.ts:137 [Extension Host] arm64
console.ts:137 [Extension Host] [WakaTime][DEBUG] Finished extracting wakatime-cli.
console.ts:137 [Extension Host] [WakaTime][DEBUG] Chmod 755 wakatime-cli...
console.ts:137 [Extension Host] arm64
console.ts:137 [Extension Host] [WakaTime][DEBUG] WakaTime: Initialized
console.ts:137 [Extension Host] [WakaTime][DEBUG] Status bar icon enabled.
2console.ts:137 [Extension Host] arm64
console.ts:137 [Extension Host] [WakaTime][DEBUG] Fetching coding activity for Today from api: /home/parallels/.wakatime/wakatime-cli-linux-amd64 --today --plugin "\"vscode/1.58.2 vscode-wakatime/14.0.0\""
console.ts:137 [Extension Host] [WakaTime][ERROR] /home/parallels/.wakatime/wakatime-cli-linux-amd64: 1: /home/parallels/.wakatime/wakatime-cli-linux-amd64: Syntax error: end of file unexpected (expecting ")")
m @ console.ts:137
$logExtensionHostMessage @ mainThreadConsole.ts:35
_doInvokeHandler @ rpcProtocol.ts:418
_invokeHandler @ rpcProtocol.ts:403
_receiveRequest @ rpcProtocol.ts:319
_receiveOneMessage @ rpcProtocol.ts:246
(anonymous) @ rpcProtocol.ts:111
fire @ event.ts:583
fire @ ipc.net.ts:513
_receiveMessage @ ipc.net.ts:866
(anonymous) @ ipc.net.ts:705
fire @ event.ts:583
acceptChunk @ ipc.net.ts:286
(anonymous) @ ipc.net.ts:247
T @ ipc.net.ts:50
emit @ events.js:315
addChunk @ internal/streams/readable.js:309
readableAddChunk @ internal/streams/readable.js:284
Readable.push @ internal/streams/readable.js:223
onStreamRead @ internal/stream_base_commons.js:188
console.ts:137 [Extension Host] [WakaTime][ERROR] Error: Command failed: /home/parallels/.wakatime/wakatime-cli-linux-amd64 --today --plugin "vscode/1.58.2 vscode-wakatime/14.0.0"/home/parallels/.wakatime/wakatime-cli-linux-amd64: 1: /home/parallels/.wakatime/wakatime-cli-linux-amd64: Syntax error: end of file unexpected (expecting ")")
m @ console.ts:137
$logExtensionHostMessage @ mainThreadConsole.ts:35
_doInvokeHandler @ rpcProtocol.ts:418
_invokeHandler @ rpcProtocol.ts:403
_receiveRequest @ rpcProtocol.ts:319
_receiveOneMessage @ rpcProtocol.ts:246
(anonymous) @ rpcProtocol.ts:111
fire @ event.ts:583
fire @ ipc.net.ts:513
_receiveMessage @ ipc.net.ts:866
(anonymous) @ ipc.net.ts:705
fire @ event.ts:583
acceptChunk @ ipc.net.ts:286
(anonymous) @ ipc.net.ts:247
T @ ipc.net.ts:50
emit @ events.js:315
addChunk @ internal/streams/readable.js:309
readableAddChunk @ internal/streams/readable.js:284
Readable.push @ internal/streams/readable.js:223
onStreamRead @ internal/stream_base_commons.js:188
console.ts:137 [Extension Host] [WakaTime][DEBUG] Fetching coding activity for Today from api: /home/parallels/.wakatime/wakatime-cli/wakatime-cli --today --plugin "\"vscode/1.58.2 vscode-wakatime/14.0.0\""
console.ts:137 [Extension Host] [WakaTime][ERROR] /home/parallels/.wakatime/wakatime-cli/wakatime-cli: 1: /home/parallels/.wakatime/wakatime-cli/wakatime-cli: �7@8@@@@@@��@@@@�u�u: not found/home/parallels/.wakatime/wakatime-cli/wakatime-cli: 1: /home/parallels/.wakatime/wakatime-cli/wakatime-cli: ��: not found/home/parallels/.wakatime/wakatime-cli/wakatime-cli: 1: /home/parallels/.wakatime/wakatime-cli/wakatime-cli: ��@@DDP�td�e�e@�e@ttQ�td/lib64/ld-linux-x86-64.so.2GNU: not found/home/parallels/.wakatime/wakatime-cli/wakatime-cli: 1: /home/parallels/.wakatime/wakatime-cli/wakatime-cli: +Pz: not found/home/parallels/.wakatime/wakatime-cli/wakatime-cli: 1: /home/parallels/.wakatime/wakatime-cli/wakatime-cli: cannot create E@@�u�uXHzlibdl.so.2_ITM_deregisterTMCloneTable__gmon_start___Jv_RegisterClasses_ITM_registerTMCloneTabledlsymdlopendlerrorlibz.so.1inflateinflateInit_inflateEndlibc.so.6__stpcpy_chk__xpg_basenamemkdtempfflushstrcpyfchmodreaddirsetlocalefopenwcsncpystrncmp__strdupperrorclosedirftellsignalstrncpymbstowcsforkunlinkmkdirstdingetpidkillstrtokfeofcallocstrlenmemsetdirnamermdirfseekclearerrunsetenv__fprintf_chkstdoutstrnlenfclose__vsnprintf_chkmallocstrcatrealpathraise__strncpy_chknl_langinfoopendirgetenvstderr__snprintf_chk__strncat_chkexecvpstrncat__realpath_chkfilenofwritefreadwaitpidstrchr__vfprintf_chk__strcpy_chk__xstat__strcat_chksetbufstrcmp__libc_start_mainferrorstpcpyfreeGLIBC_2.2.5GLIBC_2.3GLIBC_2.4GLIBC_2.3.4: File name too long/home/parallels/.wakatime/wakatime-cli/wakatime-cli: 1: /home/parallels/.wakatime/wakatime-cli/wakatime-cli: ELF: not found/home/parallels/.wakatime/wakatime-cli/wakatime-cli: 1: /home/parallels/.wakatime/wakatime-cli/wakatime-cli: Syntax error: word unexpected (expecting ")")
m @ console.ts:137
$logExtensionHostMessage @ mainThreadConsole.ts:35
_doInvokeHandler @ rpcProtocol.ts:418
_invokeHandler @ rpcProtocol.ts:403
_receiveRequest @ rpcProtocol.ts:319
_receiveOneMessage @ rpcProtocol.ts:246
(anonymous) @ rpcProtocol.ts:111
fire @ event.ts:583
fire @ ipc.net.ts:513
_receiveMessage @ ipc.net.ts:866
(anonymous) @ ipc.net.ts:705
fire @ event.ts:583
acceptChunk @ ipc.net.ts:286
(anonymous) @ ipc.net.ts:247
T @ ipc.net.ts:50
emit @ events.js:315
addChunk @ internal/streams/readable.js:309
readableAddChunk @ internal/streams/readable.js:284
Readable.push @ internal/streams/readable.js:223
onStreamRead @ internal/stream_base_commons.js:188
console.ts:137 [Extension Host] [WakaTime][ERROR] Error: Command failed: /home/parallels/.wakatime/wakatime-cli/wakatime-cli --today --plugin "vscode/1.58.2 vscode-wakatime/14.0.0"/home/parallels/.wakatime/wakatime-cli/wakatime-cli: 1: /home/parallels/.wakatime/wakatime-cli/wakatime-cli: �7@8@@@@@@��@@@@�u�u: not found/home/parallels/.wakatime/wakatime-cli/wakatime-cli: 1: /home/parallels/.wakatime/wakatime-cli/wakatime-cli: ��: not found/home/parallels/.wakatime/wakatime-cli/wakatime-cli: 1: /home/parallels/.wakatime/wakatime-cli/wakatime-cli: ��@@DDP�td�e�e@�e@ttQ�td/lib64/ld-linux-x86-64.so.2GNU: not found/home/parallels/.wakatime/wakatime-cli/wakatime-cli: 1: /home/parallels/.wakatime/wakatime-cli/wakatime-cli: +Pz: not found/home/parallels/.wakatime/wakatime-cli/wakatime-cli: 1: /home/parallels/.wakatime/wakatime-cli/wakatime-cli: cannot create E@@�u�uXHzlibdl.so.2_ITM_deregisterTMCloneTable__gmon_start___Jv_RegisterClasses_ITM_registerTMCloneTabledlsymdlopendlerrorlibz.so.1inflateinflateInit_inflateEndlibc.so.6__stpcpy_chk__xpg_basenamemkdtempfflushstrcpyfchmodreaddirsetlocalefopenwcsncpystrncmp__strdupperrorclosedirftellsignalstrncpymbstowcsforkunlinkmkdirstdingetpidkillstrtokfeofcallocstrlenmemsetdirnamermdirfseekclearerrunsetenv__fprintf_chkstdoutstrnlenfclose__vsnprintf_chkmallocstrcatrealpathraise__strncpy_chknl_langinfoopendirgetenvstderr__snprintf_chk__strncat_chkexecvpstrncat__realpath_chkfilenofwritefreadwaitpidstrchr__vfprintf_chk__strcpy_chk__xstat__strcat_chksetbufstrcmp__libc_start_mainferrorstpcpyfreeGLIBC_2.2.5GLIBC_2.3GLIBC_2.4GLIBC_2.3.4: File name too long/home/parallels/.wakatime/wakatime-cli/wakatime-cli: 1: /home/parallels/.wakatime/wakatime-cli/wakatime-cli: ELF: not found/home/parallels/.wakatime/wakatime-cli/wakatime-cli: 1: /home/parallels/.wakatime/wakatime-cli/wakatime-cli: Syntax error: word unexpected (expecting ")")
m @ console.ts:137
$logExtensionHostMessage @ mainThreadConsole.ts:35
_doInvokeHandler @ rpcProtocol.ts:418
_invokeHandler @ rpcProtocol.ts:403
_receiveRequest @ rpcProtocol.ts:319
_receiveOneMessage @ rpcProtocol.ts:246
(anonymous) @ rpcProtocol.ts:111
fire @ event.ts:583
fire @ ipc.net.ts:513
_receiveMessage @ ipc.net.ts:866
(anonymous) @ ipc.net.ts:705
fire @ event.ts:583
acceptChunk @ ipc.net.ts:286
(anonymous) @ ipc.net.ts:247
T @ ipc.net.ts:50
emit @ events.js:315
addChunk @ internal/streams/readable.js:309
readableAddChunk @ internal/streams/readable.js:284
Readable.push @ internal/streams/readable.js:223
onStreamRead @ internal/stream_base_commons.js:188
console.ts:137 [Extension Host] [WakaTime][DEBUG] Error fetching today coding activity (2); Check your /home/parallels/.wakatime.log file for more details
alanhamlett commented 3 years ago

The issue is in vscode, where it's downloading the correct Linux arm64 wakatime-cli binary but then using wakatime-cli-linux-amd64 when trying running it.

alanhamlett commented 3 years ago

We can't just use the raw output from os.arch() because we use amd64 instead of x64 so some translation is needed. For some reason the if (arch.indexOf('arm') > -1) return arch; line isn't finding arm in the output of os.arch().

@simonSlamka can you also add this line after the current console.log you've already added:

console.log(typeof arch);

simonSlamka commented 3 years ago

@simonSlamka can you also add this line after the current console.log you've already added:

console.log(typeof arch);

os.arch() returns a string

alanhamlett commented 3 years ago

@simonSlamka you have the legacy python wakatime-cli disabled in your ~/.wakatime.cfg file?

alanhamlett commented 3 years ago

We had the new Go wakatime-cli disabled when sending heartbeats, but we still used it when fetching status bar code stats. Fixed with f56f87d2a498e3114e5e40784c50097b700db4a5.

simonSlamka commented 3 years ago

@alanhamlett no, not explicitly.

the version is v1.18.9, by the way

alanhamlett commented 3 years ago

Restarting vscode should fix it for you. However, the problem will return once we re-launch the new Go wakatime-cli. To fix this for later, you'll have to re-do the symlink from this comment then add these console.log lines to src/dependencies.ts:

 34     this.global = global;
 35     console.log(this.architecture());
 36   }
437   private architecture(): string {
438     const arch = os.arch();
439     console.log(typeof arch);
440     if (arch.indexOf('32') > -1) return '386';

And let me know the output in your vscode dev console after reloading.

simonSlamka commented 3 years ago

I pulled from origin and rebuilt, then copied the extension to the vscode dir. Still the same problem, it seems. Even the output is identical.

https://github.com/wakatime/vscode-wakatime/issues/216#issuecomment-882106515

(except for the two console.log's we added)

alanhamlett commented 3 years ago

Yes, my next comment clarifies. I've deleted that wrong comment, you can ignore it since it's not correct.

alanhamlett commented 3 years ago

I found the problem, it's because the legacy wakatime-cli doesn't support arm! You should enable the new Go wakatime-cli with this line in your ~/.wakatime.cfg file:

new_beta_cli = true

Also, make sure to update the extension to v14.0.3 (latest version in the marketplace released Today) and restart VS Code.

Can you see if that fixes it for you?

jerome-diver commented 3 years ago

ok @alanhamlett it's fine now, i did what you said. Thank you very much to find and fix the problem. But please, let us know if at next step we would have to modify the wakatime.cfg file again with something other.

alanhamlett commented 3 years ago

Nothing will be needed in the future, as this just enables the beta wakatime-cli before it's launched to everyone. When it's launched, the config change won't be needed anymore but it won't hurt to leave it there.

simonSlamka commented 3 years ago

Got it.