cmder: [Bug] Got ERROR: Clink initilization has failed with error code: 0 at every start of Cmder since v1.3.21
Version Information
Cmder version: 1.3.21
Operating system: Windows 11 22H2 + december updates
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 © 2012-2018 Martin Ridgers Portions Copyright © 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
- I have read the documentation.
- I have searched for similar issues and found none that describe my issue.
- I have reproduced the issue on the latest version of Cmder.
- I am certain my issues are not related to ConEmu, Clink, or other third-party tools that Cmder uses.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 1
- Comments: 20 (12 by maintainers)
Commits related to this issue
- Return error level 2 in Clink when fatal error, related to #2800 — committed to cmderdev/cmder by DRSDavidSoft 2 years ago
@DRSDavidSoft Clink v1.4.6 was just published and includes returning exit code 2 from
clink inject
when a fatal error occurs.Please change the
if errorlevel 1
toif errorlevel 2
. That way with an updated Clink, the Cmder error message will work as intended, and with older Clink then Cmder will avoid reporting a bogus error.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.)
Good evening
Just some maybe important informations:
Maybe it is worth changing from
.bat
to.cmd
..bat
still works on the basis of 16bit MS-DOS withcommand.com
. Actually, it is a miracle that it still works 😄Additionally,
.bat
handlesErrorLevel
differently:.bat
setsErrorLevel
only in case of errors. (Source: StackOverflow)If you absolutely want to stay with
.bat
, then please work that way:Old:
New:
The new solution compares the real int value. If errorlevel is missing because of the way
.cmd
handles it, then it still works 😄Thanks a lot, kind regards, Thomas
🔥 This issue will be fixed soon, I apologize to everyone for taking too long to work on it.
@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
%errorlevel%
was at the moment line 168 was executed, not at the moment when line 201 was executed. Theinject
happens after line 168, so the errorlevel from it is not what gets shown.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 9399cbdcd7f2b787938946de95b2e07e417fbc9d added the line.
The intent was to find when Clink isn’t loaded. But the implementation was to find when Clink
inject
fails. They aren’t equivalent.The init.bat script assumes that a failed
inject
means Clink isn’t loaded. But if Clink is installed for autorun, then by the time Cmder tries to inject Clink it is already loaded and initialized. So theinject
fails, but Clink is in fact successfully initialized.The short term fix is to delete the code that attempts to detect failure to initialize. There isn’t a good long term fix at this time.
@DRSDavidSoft TIL what IRL means! 😃
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 9e55c4820006b15d91744e5b6f52c69782db084c to hopefully mitigate this issue.
@BackSpace54 Can you please:
init.bat
in your current installation, and remove line 200, 201 and 202.Cmder.exe
and typeset CMDER_ROOT
to verify that the path to Cmder root is valid.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
init.bat
to bring it in par with the scripts in the clink repository? I haven’t had time to look at the official Clink loader scripts, so I’d appreciate your feedback.