glanceapp/glance · error

location is required

Error message

location is required

What it means

Config validation in the weather widget's initialize(): the location field is empty. The widget cannot geocode or fetch a forecast without it, so initialization fails fast with a clear message rather than producing an empty widget.

Source

Thrown at internal/glance/widget-weather.go:39

	widgetBase   `yaml:",inline"`
	Location     string                      `yaml:"location"`
	ShowAreaName bool                        `yaml:"show-area-name"`
	HideLocation bool                        `yaml:"hide-location"`
	HourFormat   string                      `yaml:"hour-format"`
	Units        string                      `yaml:"units"`
	Place        *openMeteoPlaceResponseJson `yaml:"-"`
	Weather      *weather                    `yaml:"-"`
	TimeLabels   [12]string                  `yaml:"-"`
}

var timeLabels12h = [12]string{"2am", "4am", "6am", "8am", "10am", "12pm", "2pm", "4pm", "6pm", "8pm", "10pm", "12am"}
var timeLabels24h = [12]string{"02:00", "04:00", "06:00", "08:00", "10:00", "12:00", "14:00", "16:00", "18:00", "20:00", "22:00", "00:00"}

func (widget *weatherWidget) initialize() error {
	widget.withTitle("Weather").withCacheOnTheHour()

	if widget.Location == "" {
		return fmt.Errorf("location is required")
	}

	if widget.HourFormat == "" || widget.HourFormat == "12h" {
		widget.TimeLabels = timeLabels12h
	} else if widget.HourFormat == "24h" {
		widget.TimeLabels = timeLabels24h
	} else {
		return errors.New("hour-format must be either 12h or 24h")
	}

	if widget.Units == "" {
		widget.Units = "metric"
	} else if widget.Units != "metric" && widget.Units != "imperial" {
		return errors.New("units must be either metric or imperial")
	}

	return nil
}

View on GitHub (pinned to 91324e8de7)

Solutions

  1. Add location: "City, Country" to the weather widget in glance.yml
  2. Check YAML indentation — location must be a direct child of the weather widget mapping
  3. Validate the config with a YAML linter if the field seems present but is ignored

Example fix

# before
- type: weather
  # location missing

# after
- type: weather
  location: Amsterdam, Netherlands
Defensive patterns

Strategy: validation

Validate before calling

// before writing glance.yml, assert every weather widget has a location
func validateWeatherWidgets(pages []PageConfig) error {
    for _, p := range pages {
        for _, w := range p.Widgets {
            if w.Type == "weather" && strings.TrimSpace(w.Location) == "" {
                return fmt.Errorf("weather widget on page %q missing location", p.Name)
            }
        }
    }
    return nil
}

Try / catch

if err := widget.initialize(); err != nil {
    if strings.Contains(err.Error(), "location is required") {
        // config authoring mistake: fail fast with the widget's name in the message
        return fmt.Errorf("weather widget: %w", err)
    }
}

Prevention

When it happens

Trigger: A weather widget block in glance.yml with no location key, or location set to an empty string / null.

Common situations: Copy-pasting a widget template and forgetting to fill in location; YAML indentation placing location under the wrong key so it is never parsed.

Related errors


AI-assisted analysis of glanceapp/glance@91324e8de7 (2026-08-15). Data as JSON: /api/errors/12ff42eb88a18d8a. Report an issue: GitHub.