{"record":{"id":"cc48c9493b881e63","repo":"JanDeDobbeleer/oh-my-posh","slug":"no-elements-in-the-array","errorCode":null,"errorMessage":"no elements in the array","messagePattern":"no elements in the array","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/segments/nightscout.go","lineNumber":123,"sourceCode":"\t\treturn ns.options.String(FortyFiveDownIcon, \"↘\")\n\tcase \"SingleDown\":\n\t\treturn ns.options.String(SingleDownIcon, \"↓\")\n\tcase \"DoubleDown\":\n\t\treturn ns.options.String(DoubleDownIcon, \"↓↓\")\n\tdefault:\n\t\treturn \"\"\n\t}\n}\n\nfunc (ns *Nightscout) getResult() (*NightscoutData, error) {\n\tparseSingleElement := func(data []byte) (*NightscoutData, error) {\n\t\tvar result []*NightscoutData\n\t\terr := json.Unmarshal(data, &result)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\tif len(result) == 0 {\n\t\t\treturn nil, errors.New(\"no elements in the array\")\n\t\t}\n\t\treturn result[0], nil\n\t}\n\n\turl := ns.options.Template(URL, \"\", ns)\n\thttpTimeout := ns.options.Int(options.HTTPTimeout, options.DefaultHTTPTimeout)\n\n\theaders := ns.options.KeyValueMap(Headers, map[string]string{})\n\tmodifiers := func(request *http2.Request) {\n\t\tfor key, value := range headers {\n\t\t\trequest.Header.Add(key, value)\n\t\t}\n\t}\n\n\tbody, err := ns.env.HTTPRequest(url, nil, httpTimeout, modifiers)\n\tif err != nil {\n\t\treturn nil, err\n\t}","sourceCodeStart":105,"sourceCodeEnd":141,"githubUrl":"https://github.com/JanDeDobbeleer/oh-my-posh/blob/0976794618c5ed95de0985dded50de1b4dc914cb/src/segments/nightscout.go#L105-L141","documentation":"The Nightscout segment queried the configured URL (typically /api/v1/entries.json) and got a valid JSON response, but the top-level array was empty — no glucose entries exist. parseSingleElement requires at least one element to return the latest reading; an empty array means the CGM/site has no data to show.","triggerScenarios":"HTTP request succeeds but the Nightscout API returns [] — fresh install with no CGM uploads yet, monitor offline, entries purged/retention expired, or the URL points to a base path that yields an empty collection.","commonSituations":"Newly set up Nightscout instance with no sensor data, CGM disconnected overnight, wrong URL path on the Nightscout server, or querying a different profile/site with no entries.","solutions":["Verify the CGM/uploader is actively pushing entries to the Nightscout site.","Check the url option includes the correct API path (e.g. https://yoursite/api/v1/entries.json) and returns data in a browser.","If entries were purged, wait for new readings or extend data retention.","Confirm the API_SECRET/headers authenticate against a site that actually has data.","Run the query manually with curl and confirm a non-empty JSON array is returned."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":"const entries = await fetch(url).then(r => r.json())\nif (!Array.isArray(entries) || entries.length === 0) {\n  // skip segment; no CGM readings available\n}","typeGuard":"function hasEntries(data) {\n  return Array.isArray(data) && data.length > 0 && typeof data[0]?.sgv === \"number\"\n}","tryCatchPattern":"try {\n  data = parseSingleElement(body)\n} catch (e) {\n  if (e.message === \"no elements in the array\") {\n    return null // empty readings — hide segment, no retry needed\n  }\n  throw e\n}","preventionTips":["Verify the Nightscout URL returns entries in a browser/curl before wiring it up.","Ensure the CGM uploader/monitor is online and pushing readings.","Include the correct API path (e.g. /api/v1/entries.json) in the url option.","Set headers (API_SECRET) so you query the right authenticated site with data."],"tags":["nightscout","api","http","empty-response"],"backgroundTag":"empty-response-body","analyzedSha":"0976794618c5ed95de0985dded50de1b4dc914cb","analyzedAt":"2026-08-31T23:41:19.708Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}