JanDeDobbeleer/oh-my-posh · error
no location found
Error message
no location found
What it means
The OpenWeatherMap segment requires the location option. getResult validates it (as a rendered template) before calling the API and fails with this error when it is empty, since OWM's q= parameter needs a city name to geocode.
Source
Thrown at src/segments/owm.go:71
return true
}
func (d *Owm) Template() string {
return " {{ .Weather }} ({{ .Temperature }}{{ .UnitIcon }}) "
}
func (d *Owm) getResult() (*owmDataResponse, error) {
response := new(owmDataResponse)
apikey := d.options.Template(APIKey, "", d)
if apikey == "" {
return nil, errors.New("no api key found")
}
location := d.options.Template(Location, "", d)
if location == "" {
return nil, errors.New("no location found")
}
location = url.QueryEscape(location)
units := d.options.String(Units, "standard")
httpTimeout := d.options.Int(options.HTTPTimeout, options.DefaultHTTPTimeout)
d.URL = fmt.Sprintf("https://api.openweathermap.org/data/2.5/weather?q=%s&units=%s&appid=%s", location, units, apikey)
body, err := d.env.HTTPRequest(d.URL, nil, httpTimeout)
if err != nil {
return new(owmDataResponse), err
}
err = json.Unmarshal(body, &response)
if err != nil {
return new(owmDataResponse), err
}View on GitHub (pinned to 0976794618)
Solutions
- Set location to a city name, optionally with country code, e.g. "Berlin,DE".
- If location is a template, verify it renders non-empty (check the referenced env/property).
- Alternatively use the openweather segment which supports latitude/longitude if a city string is impractical.
- URL-hostile characters are fine — the segment query-escapes the value — so the issue is emptiness, not formatting.
Example fix
// before "type": "owm", "api_key": "..." // after "type": "owm", "api_key": "...", "location": "Amsterdam,NL"
Defensive patterns
Strategy: validation
Validate before calling
const loc = cfg.location?.trim()
if (!loc) {
throw new Error("owm segment requires a non-empty location, e.g. 'Berlin,DE'")
} Try / catch
if err := d.setStatus(); err != nil {
if err.Error() == "no location found" {
log.Warn("owm: set location in segment config")
return // hide segment
}
return err
} Prevention
- Set location as "City,CC" (optionally with country code) in the owm config.
- If location is a template, confirm it renders non-empty at runtime.
- When migrating between weather providers, remember OWM uses a city string, not lat/lng.
- Validate the theme config against the schema which documents the location option.
When it happens
Trigger: Configuring an owm segment with no location, location = "", or a location template that renders empty (e.g. {{ .Env.WEATHER_CITY }} unset); also empty after template expansion even if a raw value was provided.
Common situations: Themes that leave location to the user's edit, switching from a weather provider that used coordinates to OWM which expects a city string, or relying on an env var that was never exported.
Related errors
- no api key found
- missing Brewfather api key (api_key)
- missing Brewfather batch id (batch_id)
- no data found
- no location configured: set city+country or latitude+longitu
AI-assisted analysis of JanDeDobbeleer/oh-my-posh@0976794618 (2026-08-31).
Data as JSON: /api/errors/2660f4f338573eaf.
Report an issue: GitHub.