You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
bug: YAML parse error in config is silently swallowed, login overwrites all other contexts #572
A tab instead of spaces — or any YAML syntax error — in the config file causes ReadLocalConfig to return an empty config with no error, making every command behave as if the user has never logged in.
The dangerous part: login sees the empty config, treats it as a fresh install, and writes a brand-new file over it. Every other context, server, user and refresh token in the file is gone with no warning.
Root cause
localconfig.go line 103:
err=configUtil.UnmarshalLocalFile(path, &config)
ifos.IsNotExist(err) {
returnnil, nil
}
err=ValidateLocalConfig(config) // parse error is silently overwritten here
Only os.IsNotExist is handled. A YAML parse error falls through and gets immediately overwritten by ValidateLocalConfig. Same bug in ReadLocalWatchConfig.
To reproduce
Put a tab on any indented line in ~/.config/microcks/config
Run microcks context → reports "no contexts defined" instead of a parse error
Run microcks login <any-server> → the file is truncated and rewritten. All previous contexts are gone.
@lekaf974 yes, +1. It's the right way to go nesting both cases under if err != nil. Can't break
it by accidentally adding something below.
Checked all 8 callsites, they all check err != nil before the == nil check, so none of them
will treat a parse error as a "fresh install". No change needed in any of the callers.
Two more things to add to the commit:
Wrap with a Kind. Currently the same cofrom import/start/context but 20 from login/logout/stop/service/test, since KindOf defaults to KindGeneric when uReadLocalConfig
fixes it globally without modifying any callers (no import cycle — pkg/errors has no internal dependencies):
Heads up about ReadLocalWatchConfig. When running import --rt on a broken
watch file, it doesn't start off with an empty set but rather loads the existing config first. The
correct behaviour IMO, but user-visible. No impact on runtime — WatchManager.Reload already handles
Plus a regression test for both of them, currently in config_test case in #497.
I made ReadLocalConfig and ReadLocalWatchConfig return an error when the file cannot be parsed, so only a missing file returns nil with no error. I also added a test that uses a config with a tab in its indentation. (PR: #574)
Reproduced on master (f9550f5). I used a config with one tab-indented line, which makes it invalid YAML. It had two contexts (http://localhost:8080 and other-ctx).
microcks context printed no contexts defined in …/config (exit 2) instead of a parse error. The same file with the tab fixed lists both contexts.
microcks login http://localhost:<port> then exited 0 and overwrote the file: only the new context remained, and other-ctx with its server, user and tokens was gone.
Activity
gyanranjanpanda commentedon Oct 5, 2026
what is @Harsh4902 @Vaishnav88sk view on this
lekaf974 commentedon Oct 7, 2026
@gyanranjanpanda I did a quick check on current implementation and I think you are right on this
to keep existing behavior but ensure Unmarshall errors are reported properly, something like this might be enough
gyanranjanpanda commentedon Oct 7, 2026
@lekaf974 yes, +1. It's the right way to go nesting both cases under
if err != nil. Can't breakit by accidentally adding something below.
Checked all 8 callsites, they all check
err != nilbefore the== nilcheck, so none of themwill treat a parse error as a "fresh install". No change needed in any of the callers.
Two more things to add to the commit:
Wrap with a Kind. Currently the same cofrom
import/start/contextbut 20 fromlogin/logout/stop/service/test, sinceKindOfdefaults toKindGenericwhen uReadLocalConfigfixes it globally without modifying any callers (no import cycle —
pkg/errorshas no internal dependencies):Heads up about ReadLocalWatchConfig. When running import --rt on a broken
watch file, it doesn't start off with an empty set but rather loads the existing config first. The
correct behaviour IMO, but user-visible. No impact on runtime — WatchManager.Reload already handles
Plus a regression test for both of them, currently in config_test case in #497.
Harsh4902 commentedon Oct 8, 2026
Thanks @gyanranjanpanda for sharing this issue. It's really an issue, and feel free to raise a PR to fix this.
Sarthak-Shreshtha01 commentedon Oct 8, 2026
I made
ReadLocalConfigandReadLocalWatchConfigreturn an error when the file cannot be parsed, so only a missing file returns nil with no error. I also added a test that uses a config with a tab in its indentation. (PR: #574)yada commentedon Oct 14, 2026
Reproduced on master (f9550f5). I used a config with one tab-indented line, which makes it invalid YAML. It had two contexts (
http://localhost:8080andother-ctx).microcks contextprintedno contexts defined in …/config(exit 2) instead of a parse error. The same file with the tab fixed lists both contexts.microcks login http://localhost:<port>then exited 0 and overwrote the file: only the new context remained, andother-ctxwith its server, user and tokens was gone.Still valid. PR #574 targets this.