-
Notifications
You must be signed in to change notification settings - Fork 2k
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
[Bug] Got ERROR: Clink initilization has failed with error code: 0 at every start of Cmder since v1.3.21 #2800
Comments
@DRSDavidSoft I see the root causes for the two problems: 1. The error level is mistakenly reported as 0.This happens because line 201 is inside a block that started on line 168. All environment variables within a block are expanded when the block starts. So line 201 gets expanded with whatever 2. Cmder reports that Clink failed to initialize.This is due to new code that was added to init.bat, and the new code is incorrect. On 2022/10/18 commit 9399cbd added the line. The intent was to find when Clink isn't loaded. The init.bat script assumes that a failed The short term fix is to delete the code that attempts to detect failure to initialize. |
Thanks for the thorough investigation, I'll work on the short-term fix. @chrisant996 Is it possible for Clink to either report a known error level if it's already injected, or set an environment variable like CLINK_INJECTED so that we can detect and bypass re-loading it? Update: Added commit 9e55c48 to hopefully mitigate this issue. @BackSpace54 Can you please:
Please check if this fixes the issue. Thanks. @chrisant996 If it's impossible or hard to implement something to tell if Clink is already injected, I'll change the error to a warning, so the execution steps are not stopped on such a failure, and maybe the plain cmd.exe PATH is used. If clink is indeed already loaded, this won't have an effect but displaying a warning message. BTW is there anything else that you would suggest might need edits, or any additions in |
Clink itself already reports an error if injection fails due to a real error. What is the motivation behind Cmder adding an additional error message? Offhand it seems like it may be redundant.
Environment variables are inherited by every child process, so they are very unreliable for this sort of thing. E.g. once Clink is injected into one cmd.exe instance, all other processes and their children, and their grandchildren, etc all have the environment variable set. The only thing Clink can do reliably is tell whether the Clink DLL is already loaded into the process. It can't tell whether Clink has been successfully initialized or whether Clink will "work as expected". There are many ways other programs can interfere (e.g. antivirus, or programs that hook APIs and interfere with Clink's API hooks). Here's what I can do: I can explore the possibility of making
Please don't. 🙃 If Cmder reports it as a warning (or error), then everyone who installed Clink for autorun will always see the warning. Is there a reason Clink's own error reporting is insufficient?
Sorry, I don't have the capacity available to do a broad review of the init.bat script. |
Well, make this and now got ERROR: Clink initialization has failed with error code: 1 at each start of Cmder. See below ╭─ C:\Temp at 10:12:16 ╭─ C:\Temp at 10:12:20 ╭─ C:\Temp at 10:12:27 Click to show...19/12/2022 09:35 DIR . 21/12/2022 08:58 DIR .. 19/12/2022 09:35 7 .cmderver 14/12/2022 12:52 147 713 CHANGES 14/12/2022 12:52 1 499 clink.bat 14/12/2022 12:54 823 242 clink.html 14/12/2022 12:52 120 546 clink.ico 14/12/2022 12:52 247 clink.lua 14/12/2022 12:52 34 494 clink_blue.ico 14/12/2022 12:52 34 494 clink_cyan.ico 14/12/2022 12:53 1 831 936 clink_dll_x64.dll 14/12/2022 12:53 1 476 096 clink_dll_x86.dll 14/12/2022 12:52 34 494 clink_gold.ico 14/12/2022 12:52 34 494 clink_gray.ico 14/12/2022 12:52 34 494 clink_green.ico 14/12/2022 12:52 34 494 clink_orange.ico 14/12/2022 12:52 34 494 clink_purple.ico 14/12/2022 12:52 34 494 clink_red.ico 14/12/2022 12:53 4 608 clink_x64.exe 14/12/2022 12:53 4 096 clink_x86.exe 14/12/2022 12:52 35 823 LICENSE 14/12/2022 12:52 539 _default_inputrc 14/12/2022 12:52 1 581 _default_settings ╭─ C:\Temp at 10:12:51 Click to show...21/12/2022 10:12 DIR . 19/12/2022 18:56 DIR .. 21/12/2022 10:12 5 352 clink.log 21/12/2022 09:00 25 337 clink_history 19/12/2022 19:03 3 423 clink_settings 16/01/2022 22:05 1 959 cmder_prompt_config.lua 18/09/2022 10:11 72 281 flexprompt.lua 19/05/2022 20:42 1 137 flexprompt_autoconfig.lua 31/08/2022 10:27 61 894 flexprompt_modules.lua 20/09/2022 03:27 35 851 flexprompt_wizard.lua 19/12/2022 09:34 DIR profile.d 19/12/2022 09:34 887 Readme.md 19/05/2022 11:19 54 781 user-ConEmu.xml 19/05/2022 14:07 437 user_aliases.cmd 16/01/2022 22:05 721 user_profile.cmd ╭─ C:\Temp at 10:13:06 Click to show...21/12/2022 08:58 DIR . 19/12/2022 18:56 DIR .. 19/12/2022 09:34 DIR bin 19/12/2022 09:35 DIR clink 01/12/2022 22:09 DIR clink-completions 19/12/2022 09:34 21 549 clink.lua 19/12/2022 09:34 726 clink_settings.default 19/12/2022 09:34 4 016 cmder_exinit 19/12/2022 09:34 2 477 cmder_prompt_config.lua.default 19/12/2022 09:35 DIR conemu-maximus5 19/12/2022 09:34 56 225 ConEmu.xml.default 19/12/2022 18:41 DIR git-for-windows 16/01/2022 22:05 29 git-for-windows_1.29.1 19/12/2022 09:34 16 597 init - Copie.bat 21/12/2022 09:05 16 313 init.bat 19/12/2022 09:34 DIR lib 19/12/2022 09:34 9 725 profile.ps1 19/12/2022 09:34 DIR psmodules 19/12/2022 09:34 49 Readme.md 19/12/2022 09:34 689 sources.json 19/12/2022 09:34 682 user_aliases.cmd.default 19/12/2022 09:34 740 user_profile.cmd.default 19/12/2022 09:34 902 user_profile.ps1.default 19/12/2022 09:34 301 user_profile.sh.default ╭─ C:\Temp at 10:13:39 ╭─ C:\Temp exit 1 at 10:13:40 clink.log from above command (at 10:13:39) is Click to show...42b0 start_logger 160 ---- 2022/12/21 10:13:39.471 ------------------------------------------------- 42b0 start_logger 166 Host process is 'cmd.exe' (pid 17072) 42b0 start_logger 170 DLL path is 'C:\Program Files (x86)\clink' 42b0 start_logger 185 Windows version 10.0.22621 (x64) 42b0 start_logger 187 Clink version 1.4.5.2e84bc (x64) 42b0 history_db::compact 1526 History: 703 active, 391 deleted 42b0 reset_handle 144 resetting mismatched stdout handle 42b0 reset_handle 144 resetting mismatched stderr handle 42b0 history_db::compact 1526 History: 703 active, 391 deleted |
@DRSDavidSoft the new commit seems to still have both of the problems I noted earlier. Using Also, the |
Good evening Just some maybe important informations:
If you absolutely want to stay with Old:
New:
The new solution compares the real int value. If errorlevel is missing because of the way Thanks a lot, kind regards, |
Huh?
Both .bat and .cmd files are run by cmd.exe on Windows.
That is not a general difference -- it applies only to the commands PATH/APPEND/PROMPT/SET/ASSOC, and only when Command Extensions are enabled. And that's the only difference between how cmd.exe runs .bat files versus .cmd files. Using .bat and .cmd are interchangeable for practical purposes.
I'm sorry, but that is dangerous advice: Using Using The suggested approach is unreliable and creates the opportunity for weird malfunctions. It's safer to use the Also: please don't check errorlevel after Clink |
@DRSDavidSoft Clink v1.4.6 was just published and includes returning exit code 2 from Please change the And there's little point in showing the %errorlevel% in the error message, since it will always be the same value; it is not an error code that can be looked up anywhere for diagnostic purposes, it is simply a "yes/no" value. So, please remove the %errorlevel% mentioned in the error message. (That way you can sidestep needing to restructure the code to report the actual errorlevel -- since the way it's currently written it prints whatever %errorlevel% was at line 168, which is completely unrelated to the error at line 201. This is because of how variable expansion works in parenthesis groupings. For more info, refer to "Delayed Expansion" for cmd.exe.) |
Just met the same issue in the latest version of cmder. |
+1 |
🔥 This issue will be fixed soon, I apologize to everyone for taking too long to work on it. |
No problem 😺 |
@DRSDavidSoft just a reminder, this needs a fix. Why were these lines added?
Options:
(Also, see this reply about why some other recent feedback is incorrect and should not be applied.) |
@chrisant996 Hi, I'm so sorry for taking so long as I was busy with a couple of IRL things. Thanks for the explanation, I added this commit to hopefully fix the issue: Basically, what I understood from your description is that if clink is executed and then is ran into a problem, it will display its own messages and then exit with the appropriate error message, thus it's unnecessary for Cmder (and ill-advised) to print a second message to the screen. The most suitable action it can do is to log the error somewhere, and maybe change its course of action. My initial intention was to detect if the injection of Clink failed, show some proper error messages to the user, and then revert back to the vanilla Cmd shell with Cmder's prompt (see code in SKIP_CLINK section). Please note that this failure might also arise when the Clink executable is not launched, for example if an anti-virus software prevented Clink from being executed, or if somehow clink.exe was missing on the target machine's Cmder installation, or if the CPU instruction set doesn't match, etc. For now, I have removed the error message since it was causing more problems and used the error level of 2 to jump to the SKIP_CLINK label. Ideally, I believe I should account for any other error levels (besides 0 and 1) as well.
If the above seems right to you, please let me know so that I can implement it. Additionally, please review the changes at e9750ab and let me know if it fixes this issue. Tests by the OP @BackSpace54 and also @pmsobrado will be appreciated |
Hey @DRSDavidSoft I've been testing the build and the error is not present anymore, but I would like to point out a few things I've noticed about the clink injection behaviour (also present in past builds, not only this new one): 1 - For people like my that already have clink injected on cmd, the history is not available if using cmder. If I change the Running Now, why is clink and the lambda/colors of the command window related? Aren't we injecting clink twice, one from the system and one from cmder? Thanks! |
@DRSDavidSoft TIL what IRL means! :-) |
Hi @pmsobrado, since my comment turned out to be so long, I posted it over discussions here: #2856 as it already was off-topic regarding this issue. I think @chrisant996 might also have a say, so I invite all to reply over the new discussions page. @daxgames Cool! BTW I'm planning to next review & merge your amazing speed PR. I have some ideas on how to improve it as well. Sorry it's taking this long, I had multiple projects & problems to deal with. Hopefully I'll be free soon. Thanks! 👍🏻 |
@pmsobrado @DRSDavidSoft I'll respond in #2856. |
@DRSDavidSoft @chrisant996 see you there! |
Workaround is to add If clink autodetection is difficult, then maybe just add a setting "Do not init clink" or something like that. |
Version Information
Cmder Edition
Cmder Full (with Git)
Description of the issue
Hi,
since i've updated to the latest Cmder version to date (v1.3.21) and with Clink 1.4.4, i've an error at terminal startup:
Clink v1.4.4.7fe1ca
Copyright (c) 2012-2018 Martin Ridgers
Portions Copyright (c) 2020-2022 Christopher Antos
https://github.com/chrisant996/clink
ERROR: Clink initilization has failed with error code: 0
Before Cmder 1.3.21 and with the exact same configuration (clink 1.4.4 i mean) i've no troubles.
The error message is from init.bat line #201 (see here)
Have you an idea of what is the problem?
Can i delete the condition at line #200?
Btw there's a typo at line #201 it's initialization not initilization ;-)
Bye.
How to reproduce
Use Windows 11 22H2
Update/install Cmder 1.3.21
Install Clink 1.4.1
Set this run command in Windows Terminal
cmd.exe /k %SYSTEMDRIVE%\<Cmder directory>\vendor\init.bat
Run Cmder tab, at each start got the message
ERROR: Clink initilization has failed with error code: 0
Additional context
Got a reply from Clink's author and it's not a Clink bug.
Checklist
The text was updated successfully, but these errors were encountered: