Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

bug: YAML parse error in config is silently swallowed, login overwrites all other contexts

未关闭 适合新手
#572 6 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@Sarthak-Shreshtha01 已经在做这个了。

开始于 2026年10月8日。

  • #574 来自 @Sarthak-Shreshtha01 —— 未关闭

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
76/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
go
领域
cli, testing

调研方向

从 localconfig.go 第 103 行附近开始,比较 ReadLocalConfig 和 ReadLocalWatchConfig 如何处理 configUtil.UnmarshalLocalFile 返回的错误。然后阅读 config_test.go,为两个读取器添加针对格式错误 YAML 的测试。完成标准是返回解析错误,而不是将其视为空配置;文件缺失时仍返回 nil, nil。

由索引模型根据 Issue 内容生成。

描述

component/cli kind/bug

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)
if os.IsNotExist(err) {
    return nil, 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

  1. Put a tab on any indented line in ~/.config/microcks/config
  2. Run microcks context → reports "no contexts defined" instead of a parse error
  3. Run microcks login <any-server> → the file is truncated and rewritten. All previous contexts are gone.

Fix

if err != nil {
    return nil, fmt.Errorf("reading config %s: %w", path, err)
}

Same in ReadLocalWatchConfig. After this, nil, nil keeps its only meaning — file doesn't exist — and fresh-install logic stays untouched.

There is no test for malformed input in config_test.go, which is how this went unnoticed.

主要语言
Go
星标
58
派生
72
平均合并
1 天 11 小时
30 天内合并 PR
27

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

microcks/microcks-cli 的其他 Issue

查看 microcks/microcks-cli 的全部 Issue

相似的 Issue

更多 Go Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。