{"record":{"id":"1f61f4942f5a3844","repo":"JanDeDobbeleer/oh-my-posh","slug":"no-api-key-found","errorCode":null,"errorMessage":"no api key found","messagePattern":"no api key found","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/segments/owm.go","lineNumber":66,"sourceCode":"\n\tif err != nil {\n\t\tlog.Error(err)\n\t\treturn false\n\t}\n\n\treturn true\n}\n\nfunc (d *Owm) Template() string {\n\treturn \" {{ .Weather }} ({{ .Temperature }}{{ .UnitIcon }}) \"\n}\n\nfunc (d *Owm) getResult() (*owmDataResponse, error) {\n\tresponse := new(owmDataResponse)\n\n\tapikey := d.options.Template(APIKey, \"\", d)\n\tif apikey == \"\" {\n\t\treturn nil, errors.New(\"no api key found\")\n\t}\n\n\tlocation := d.options.Template(Location, \"\", d)\n\tif location == \"\" {\n\t\treturn nil, errors.New(\"no location found\")\n\t}\n\n\tlocation = url.QueryEscape(location)\n\n\tunits := d.options.String(Units, \"standard\")\n\thttpTimeout := d.options.Int(options.HTTPTimeout, options.DefaultHTTPTimeout)\n\n\td.URL = fmt.Sprintf(\"https://api.openweathermap.org/data/2.5/weather?q=%s&units=%s&appid=%s\", location, units, apikey)\n\n\tbody, err := d.env.HTTPRequest(d.URL, nil, httpTimeout)\n\tif err != nil {\n\t\treturn new(owmDataResponse), err\n\t}","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/JanDeDobbeleer/oh-my-posh/blob/0976794618c5ed95de0985dded50de1b4dc914cb/src/segments/owm.go#L48-L84","documentation":"The OpenWeatherMap segment requires the api_key option, resolved as a template. getResult rejects the request before any HTTP call when the template renders to an empty string, because OWM's API cannot authenticate without an appid.","triggerScenarios":"Configuring an owm segment without api_key, with api_key = \"\", or with a template/property that resolves to empty at runtime (e.g. referencing a missing env var like {{ .Env.OWM_KEY }} that is unset).","commonSituations":"Copy-pasting a theme that expects an env var you never set, redacting the key when sharing config and forgetting to restore it, or a template typo producing an empty string.","solutions":["Set api_key to a valid OpenWeatherMap API key in the segment config.","If using a template like {{ .Env.OWM_API_KEY }}, export that environment variable before launching the shell.","Remove surrounding quotes/whitespace issues so the template does not render empty.","Get a free key from openweathermap.org if you do not have one."],"exampleFix":"// before\n{\n  \"type\": \"owm\"\n}\n// after\n{\n  \"type\": \"owm\",\n  \"api_key\": \"your-openweathermap-appid\"\n}","handlingStrategy":"validation","validationCode":"const key = process.env.OWM_API_KEY ?? cfg.api_key ?? \"\"\nif (!key) {\n  throw new Error(\"owm segment requires a non-empty api_key\")\n}","typeGuard":null,"tryCatchPattern":"err := d.setStatus()\nif err != nil {\n  if err.Error() == \"no api key found\" {\n    log.Warn(\"owm: set api_key in segment config\")\n    return // hide segment\n  }\n  return err\n}","preventionTips":["Always set api_key in the owm segment config.","If the key comes from a template/env reference, verify the env var is exported in the shell that starts oh-my-posh.","Test the key against api.openweathermap.org before deploying it into the theme.","Keep keys out of VCS but out of quotes-only typos too — validate the config renders non-empty."],"tags":["config","api-key","openweathermap","weather"],"backgroundTag":"missing-api-key","analyzedSha":"0976794618c5ed95de0985dded50de1b4dc914cb","analyzedAt":"2026-08-31T23:41:19.708Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}