Skip to content

pkg/config: accept string shorthand for the projects list#53

Merged
textfuel merged 2 commits intotextfuel:mainfrom
SAY-5:fix/projects-string-shorthand
Apr 18, 2026
Merged

pkg/config: accept string shorthand for the projects list#53
textfuel merged 2 commits intotextfuel:mainfrom
SAY-5:fix/projects-string-shorthand

Conversation

@SAY-5
Copy link
Copy Markdown
Contributor

@SAY-5 SAY-5 commented Apr 17, 2026

Problem

The config schema declares

type Config struct {
    ...
    Projects []ProjectConfig `yaml:"projects"`
}

type ProjectConfig struct {
    Key     string `yaml:"key"`
    BoardID int    `yaml:"boardId"`
}

so the most natural form that users reach for:

projects:
  - ORCH
  - PLAT

errors out of yaml.v3 with cannot unmarshal !!str into config.ProjectConfig.
On v2.8.1 this bubbled up through cfg, _ := config.Load() as a nil *Config
and crashed with a SIGSEGV the moment resolveClient touched cfg.Jira.Host
(#41). main.go already returns the error cleanly, so the crash itself is
gone, but the shorthand form still isn't accepted.

Fix

Add UnmarshalYAML to ProjectConfig so it accepts either form:

projects:
  - ORCH            # scalar: Key only, BoardID defaults to 0
  - key: DATA       # mapping: full form
    boardId: 7

Scalar nodes are decoded straight into Key. Mapping nodes go through a
local type alias so the method doesn't recurse into itself. Added a test
that covers both forms in the same list.

Refs #41

@SAY-5 SAY-5 requested a review from textfuel as a code owner April 17, 2026 20:17
textfuel
textfuel previously approved these changes Apr 18, 2026
Copy link
Copy Markdown
Owner

@textfuel textfuel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean fix, thx!

@textfuel
Copy link
Copy Markdown
Owner

could you resolve the merge conflicts with main so I can merge

A config.yml entry of the form

	projects:
	  - ORCH

panicked lazyjira on startup with
	panic: runtime error: invalid memory address or nil pointer dereference
		main.resolveClient(0x0)
			cmd/lazyjira/main.go:155 +0xc0

because `projects:` is typed as []ProjectConfig. yaml.v3 refuses to map
a scalar into a struct and returns "cannot unmarshal !!str into
config.ProjectConfig", which Load() propagated as (nil, err) and
resolveClient happily dereferenced anyway.

Give ProjectConfig a custom UnmarshalYAML that treats scalar nodes as
the Key value and falls through to the normal struct decode for full
mapping nodes. A type alias is used for the struct branch so the
fallthrough does not recurse into this method. Both forms can now be
mixed in the same list, which matches what the docs / README imply
when they show single-string entries.

Fixes textfuel#41

Signed-off-by: SAY-5 <[email protected]>
@SAY-5 SAY-5 force-pushed the fix/projects-string-shorthand branch from eaa9c8c to 48b8c56 Compare April 18, 2026 07:25
@SAY-5
Copy link
Copy Markdown
Contributor Author

SAY-5 commented Apr 18, 2026

Thanks for the review! Rebased on top of latest main, conflicts resolved. Ready to merge when you are.

@textfuel textfuel merged commit 5728a57 into textfuel:main Apr 18, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants