Skip to content

ParseDestinations silently drops the first URL when loaded from a config file #5

Open

Description

@dolph

Summary

ParseDestinations skips index 0 of the URL slice unconditionally. That is correct for CLI invocation (where index 0 is the subcommand, e.g. check), but it is wrong when URLs come from the YAML config file — silently dropping the first configured destination.

Reproduction

connectivity.yml:

A: https://example.com
B: https://github.com
$ connectivity check       # no URLs on the CLI, so config.URLs is used
$ connectivity validate-config

Only one of the two destinations will be parsed/checked. Which one is dropped is non-deterministic because Go map iteration order is randomized.

Code

connectivity.go:107-126:

func ParseDestinations(urls []Url) []*Destination {
	errEncountered := false
	var destinations []*Destination
	for idx, url := range urls {
		if idx != 0 {                       // <-- always skips first entry
			dest, err := NewDestination(url)
			...
		}
	}
	...
}

connectivity.go:95-105 shows why this works for CLI but fails for config:

func GetURLs(config *Config) []Url {
	if len(os.Args) > 2 {
		// CLI path: prepends the subcommand at idx 0
		config.URLs = []Url{}
		for _, url := range os.Args[1:len(os.Args)] {
			config.URLs = append(config.URLs, Url{Url: url})
		}
	}
	return config.URLs                     // config path: no subcommand prefix
}

validate-config is affected too — it calls ParseDestinations(config.URLs) directly with no synthetic prefix (connectivity.go:38).

Impact

Silent data loss: a configured destination is never checked, but connectivity check still reports success on the remaining ones. This makes the tool unreliable as a pre-deploy gate.

Suggested fix

Strip the subcommand at the source (in GetURLs) rather than in ParseDestinations. For example:

for _, url := range os.Args[2:] {          // start after the subcommand
    config.URLs = append(config.URLs, Url{Url: url})
}

and have ParseDestinations iterate every element with no special-casing of index 0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions