{"record":{"id":"c94f976b34787278","repo":"JanDeDobbeleer/oh-my-posh","slug":"date-field-must-be-a-valid-number-got-s","errorCode":null,"errorMessage":"date field must be a valid number, got: %s","messagePattern":"date field must be a valid number, got: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/segments/nightscout.go","lineNumber":76,"sourceCode":"\tif err := json.Unmarshal(data, aux); err != nil {\n\t\treturn err\n\t}\n\n\tif aux.Date == \"\" {\n\t\treturn nil\n\t}\n\n\tif i, err := aux.Date.Int64(); err == nil {\n\t\tn.Date = i\n\t\treturn nil\n\t}\n\n\tif f, err := aux.Date.Float64(); err == nil {\n\t\tn.Date = int64(f)\n\t\treturn nil\n\t}\n\n\treturn fmt.Errorf(\"date field must be a valid number, got: %s\", aux.Date)\n}\n\nfunc (ns *Nightscout) Template() string {\n\treturn \" {{ .Sgv }} \"\n}\n\nfunc (ns *Nightscout) Enabled() bool {\n\tdata, err := ns.getResult()\n\tif err != nil {\n\t\treturn false\n\t}\n\tns.NightscoutData = *data\n\tns.TrendIcon = ns.getTrendIcon()\n\n\treturn true\n}\n\nfunc (ns *Nightscout) getTrendIcon() string {","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/JanDeDobbeleer/oh-my-posh/blob/0976794618c5ed95de0985dded50de1b4dc914cb/src/segments/nightscout.go#L58-L94","documentation":"Nightscout entries carry their date as a JSON field that must deserialize into a numeric (unix) timestamp. The custom UnmarshalJSON first tries a direct JSON number, then a string-encoded number; if the Date field is neither, it errors with 'date field must be a valid number, got: <raw>'.","triggerScenarios":"Unmarshaling a Nightscout API response whose `date` field is a non-numeric string (e.g. an ISO-8601 timestamp like \"2024-01-01T12:00:00Z\", or null), instead of a numeric or numeric-string epoch value.","commonSituations":"Nightscout server configured to emit ISO date strings (different plugin/version); a proxy or mock returning null dates; hitting a different endpoint whose schema differs from the expected entries format.","solutions":["Check the raw JSON your Nightscout URL returns and confirm `date` is an epoch number or numeric string","Configure the Nightscout server/API version to return epoch-based dates (date field as number)","Update oh-my-posh in case a newer version handles ISO date strings","If you control the middleware, convert ISO timestamps to epoch ms before the response reaches the segment"],"exampleFix":"// before (API response)\n{ \"sgv\": 120, \"date\": \"2024-01-01T12:00:00.000Z\" }\n// after\n{ \"sgv\": 120, \"date\": 1704110400000 }","handlingStrategy":"type-guard","validationCode":"// validate the date field before unmarshaling\nvar raw struct { Date json.RawMessage `json:\"date\"` }\njson.Unmarshal(body, &raw)\nvar num float64\nif err := json.Unmarshal(raw.Date, &num); err != nil {\n    // date is not numeric (e.g. ISO string) — fix source data\n}","typeGuard":"func isNumericDate(v json.RawMessage) bool {\n    var n float64\n    return json.Unmarshal(v, &n) == nil\n}","tryCatchPattern":"// caller-side: tolerate malformed entries\nvar entries []Nightscout\nif err := json.Unmarshal(body, &entries); err != nil {\n    // render no glucose data rather than failing the prompt\n}","preventionTips":["Verify your Nightscout server emits epoch-numeric date fields","Test the raw API response with curl/jq before wiring the segment","Keep oh-my-posh updated for schema tolerance","Avoid proxies that rewrite the JSON payload"],"tags":["go","json","unmarshal","type-mismatch","api"],"backgroundTag":"json-type-mismatch","analyzedSha":"0976794618c5ed95de0985dded50de1b4dc914cb","analyzedAt":"2026-08-31T23:41:19.708Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}