JanDeDobbeleer/oh-my-posh · warning

no elements in the array

Error message

no elements in the array

What it means

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.

Source

Thrown at src/segments/nightscout.go:123

		return ns.options.String(FortyFiveDownIcon, "↘")
	case "SingleDown":
		return ns.options.String(SingleDownIcon, "↓")
	case "DoubleDown":
		return ns.options.String(DoubleDownIcon, "↓↓")
	default:
		return ""
	}
}

func (ns *Nightscout) getResult() (*NightscoutData, error) {
	parseSingleElement := func(data []byte) (*NightscoutData, error) {
		var result []*NightscoutData
		err := json.Unmarshal(data, &result)
		if err != nil {
			return nil, err
		}
		if len(result) == 0 {
			return nil, errors.New("no elements in the array")
		}
		return result[0], nil
	}

	url := ns.options.Template(URL, "", ns)
	httpTimeout := ns.options.Int(options.HTTPTimeout, options.DefaultHTTPTimeout)

	headers := ns.options.KeyValueMap(Headers, map[string]string{})
	modifiers := func(request *http2.Request) {
		for key, value := range headers {
			request.Header.Add(key, value)
		}
	}

	body, err := ns.env.HTTPRequest(url, nil, httpTimeout, modifiers)
	if err != nil {
		return nil, err
	}

View on GitHub (pinned to 0976794618)

Solutions

  1. Verify the CGM/uploader is actively pushing entries to the Nightscout site.
  2. Check the url option includes the correct API path (e.g. https://yoursite/api/v1/entries.json) and returns data in a browser.
  3. If entries were purged, wait for new readings or extend data retention.
  4. Confirm the API_SECRET/headers authenticate against a site that actually has data.
  5. Run the query manually with curl and confirm a non-empty JSON array is returned.
Defensive patterns

Strategy: type-guard

Validate before calling

const entries = await fetch(url).then(r => r.json())
if (!Array.isArray(entries) || entries.length === 0) {
  // skip segment; no CGM readings available
}

Type guard

function hasEntries(data) {
  return Array.isArray(data) && data.length > 0 && typeof data[0]?.sgv === "number"
}

Try / catch

try {
  data = parseSingleElement(body)
} catch (e) {
  if (e.message === "no elements in the array") {
    return null // empty readings — hide segment, no retry needed
  }
  throw e
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of JanDeDobbeleer/oh-my-posh@0976794618 (2026-08-31). Data as JSON: /api/errors/cc48c9493b881e63. Report an issue: GitHub.