JanDeDobbeleer/oh-my-posh · error

unclosed section:

Error message

unclosed section: 

What it means

The ini parser treats a line starting with '[' as a section header and requires a closing ']'. strings.CutLast fails to find ']' so the line is malformed. The error echoes the offending line so you can spot the typo in the loaded config.

Source

Thrown at src/ini/ini.go:54

}

func parse(src string, verbatim bool) (*File, error) {
	file := &File{sections: make(map[string]*Section)}

	src = strings.TrimPrefix(src, "\ufeff")
	current := file.section("")

	for line := range strings.Lines(src) {
		line = strings.TrimSpace(line)

		if line == "" || line[0] == '#' || line[0] == ';' {
			continue
		}

		if line[0] == '[' {
			name, _, found := strings.CutLast(line, "]")
			if !found {
				return nil, errors.New("unclosed section: " + line)
			}

			current = file.section(strings.TrimSpace(name[1:]))
			continue
		}

		delim := strings.IndexAny(line, "=:")
		if delim < 0 {
			return nil, errors.New("key-value delimiter not found: " + line)
		}

		name := strings.TrimSpace(line[:delim])
		value := parseValue(line[delim+1:], verbatim)

		if _, ok := current.keys[name]; ok {
			continue
		}

View on GitHub (pinned to 0976794618)

Solutions

  1. Open the config file and add the missing ']' to the reported line, e.g. '[section]'
  2. Escape or comment out the stray bracket line if it isn't meant to be a section
  3. Validate the file with a TOML/INI linter before loading

Example fix

// before (file content)
[segment
// after (file content)
[segment]
Defensive patterns

Strategy: validation

Validate before calling

for i, line := range lines {
    if strings.HasPrefix(strings.TrimSpace(line), "[") && !strings.Contains(line, "]") {
        return fmt.Errorf("line %d: unclosed section header", i+1)
    }
}

Type guard

func isClosedSectionLine(line string) bool {
    return !strings.HasPrefix(line, "[") || strings.Contains(line, "]")
}

Try / catch

file, err := ini.Load(path)
if err != nil {
    if strings.Contains(err.Error(), "unclosed section") {
        return fmt.Errorf("config %s malformed: %w", path, err)
    }
    return err
}

Prevention

When it happens

Trigger: parse() (via Load or LoadVerbatim) encounters a line whose first byte is '[' but has no ']' anywhere in it - e.g. '[section' or a stray bracket line like '[TODO fix this'.

Common situations: Hand-edited oh-my-posh theme/config files with a truncated section header; copy-paste losing the closing bracket; a comment line accidentally starting with '['.

Related errors


AI-assisted analysis of JanDeDobbeleer/oh-my-posh@0976794618 (2026-08-31). Data as JSON: /api/errors/a6cab20037a9f5a9. Report an issue: GitHub.