{"record":{"id":"7ce5eff5f26712f3","repo":"666ghj/MiroFish","slug":"reconstruction-date-must-be-a-string","errorCode":null,"errorMessage":"reconstruction date must be a string","messagePattern":"reconstruction date must be a string","errorType":"exception","errorClass":"StarHistoryError","httpStatus":null,"severity":"error","filePath":"scripts/star_history.py","lineNumber":404,"sourceCode":"        raise StarHistoryError(\"unsupported reconstruction method\")\n    generated_at = _parse_state_timestamp(\n        reconstruction[\"generated_at\"], \"reconstruction.generated_at\"\n    )\n    daily = reconstruction[\"daily\"]\n    if not isinstance(daily, list):\n        raise StarHistoryError(\"reconstruction.daily must be a list\")\n    if reconstruction_method == \"aggregate_snapshot_only\" and daily:\n        raise StarHistoryError(\"aggregate-only history cannot contain reconstructed dates\")\n\n    previous_day: date | None = None\n    previous_stars = 0\n    for index, raw_point in enumerate(daily):\n        if not isinstance(raw_point, dict):\n            raise StarHistoryError(\"reconstruction point must be an object\")\n        _expect_keys(raw_point, {\"date\", \"stars\"}, \"reconstruction point\")\n        raw_date = raw_point[\"date\"]\n        if not isinstance(raw_date, str):\n            raise StarHistoryError(\"reconstruction date must be a string\")\n        try:\n            point_day = date.fromisoformat(raw_date)\n        except ValueError as exc:\n            raise StarHistoryError(\"reconstruction date is invalid\") from exc\n        if point_day.isoformat() != raw_date:\n            raise StarHistoryError(\"reconstruction date is not canonical\")\n        stars = _strict_non_negative_int(raw_point[\"stars\"], \"reconstruction stars\")\n        if index == 0 and stars <= 0:\n            raise StarHistoryError(\"first reconstruction point must have stars\")\n        if previous_day is not None and point_day <= previous_day:\n            raise StarHistoryError(\"reconstruction dates must be strictly increasing\")\n        if index > 0 and stars <= previous_stars:\n            raise StarHistoryError(\"reconstruction stars must be strictly increasing\")\n        if point_day >= generated_at.date():\n            raise StarHistoryError(\"reconstruction must contain only completed UTC dates\")\n        previous_day = point_day\n        previous_stars = stars\n","sourceCodeStart":386,"sourceCodeEnd":422,"githubUrl":"https://github.com/666ghj/MiroFish/blob/b5b53acc57189a4a42e44a23e149dc655c98fe82/scripts/star_history.py#L386-L422","documentation":"Raised by validate_state() when a daily point's 'date' field is not a Python str (JSON string). The date must be an ISO-format string that is subsequently parsed with date.fromisoformat, so non-string types fail before parsing is attempted.","triggerScenarios":"validate_state(state) where a daily point has date: 20240101 (number), date: null, or date: {\"year\": 2024, ...}.","commonSituations":"Programmatic generation where a datetime.date object was serialized incorrectly or an int-encoded date was used to save space; hand-edited files.","solutions":["Emit dates as strings in 'YYYY-MM-DD' form","When generating state in Python, use point_day.isoformat() rather than str/int conversions","Regenerate state rather than patching individual fields by hand"],"exampleFix":"// before\n{\"date\": 20240101, \"stars\": 10}\n// after\n{\"date\": \"2024-01-01\", \"stars\": 10}","handlingStrategy":"type-guard","validationCode":"for p in state[\"reconstruction\"][\"daily\"]:\n    if not isinstance(p[\"date\"], str):\n        p[\"date\"] = p[\"date\"].isoformat() if hasattr(p[\"date\"], \"isoformat\") else str(p[\"date\"])","typeGuard":"def has_string_dates(daily: list) -> bool:\n    return all(isinstance(p.get(\"date\"), str) for p in daily)","tryCatchPattern":"try:\n    validate_state(state)\nexcept StarHistoryError as exc:\n    if \"reconstruction date must be a string\" in str(exc):\n        # coerce date objects to ISO strings, then re-validate\n        ...","preventionTips":["Always call .isoformat() on date objects when writing JSON","Never rely on implicit str(date) formatting differing from ISO","Type-check producer payloads before serialization"],"tags":["validation","date","state-file"],"backgroundTag":null,"analyzedSha":"b5b53acc57189a4a42e44a23e149dc655c98fe82","analyzedAt":"2026-08-14T22:29:33.146Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}