{"record":{"id":"c6abbf586e8460a0","repo":"HKUDS/Vibe-Trading","slug":"field-name-is-required-and-cannot-be-empty","errorCode":null,"errorMessage":"{field_name} is required and cannot be empty","messagePattern":"(.+?) is required and cannot be empty","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"agent/src/entities/models.py","lineNumber":89,"sourceCode":"    Codes are upper-cased and stripped. Length is deliberately not constrained\n    to three characters: this project also handles crypto quote assets such as\n    ``USDT``, and rejecting them would push callers into faking a code.\n\n    Args:\n        value: Raw currency code, e.g. ``\" usd \"``.\n        field_name: Name used in the error message, for caller context.\n\n    Returns:\n        The canonical code, e.g. ``\"USD\"``.\n\n    Raises:\n        ValueError: If the code is empty, not a string, or contains whitespace.\n    \"\"\"\n    if not isinstance(value, str):\n        raise ValueError(f\"{field_name} must be a string, got {type(value).__name__}\")\n    cleaned = value.strip().upper()\n    if not cleaned:\n        raise ValueError(f\"{field_name} is required and cannot be empty\")\n    if any(ch.isspace() for ch in cleaned):\n        raise ValueError(f\"{field_name} cannot contain whitespace, got {value!r}\")\n    return cleaned\n\n\ndef normalize_date(value: date | datetime | str, *, field_name: str = \"date\") -> date:\n    \"\"\"Coerce a supported date input to a plain ``datetime.date``.\n\n    ``datetime`` instances are truncated to their date, because a cash flow\n    settles on a day, not at a timestamp; keeping the time component would make\n    two flows on the same day compare unequal for no economic reason.\n\n    Strings must be ISO-8601 (``YYYY-MM-DD``, optionally with a time part).\n    Ambiguous regional formats such as ``03/04/2024`` are rejected rather than\n    guessed, since guessing day-first vs month-first is a silent wrong answer.\n\n    Args:\n        value: A ``date``, a ``datetime``, or an ISO-8601 string.","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/HKUDS/Vibe-Trading/blob/80ffdda44c5c4db0dd84d70e051cca591cea67df/agent/src/entities/models.py#L71-L107","documentation":"normalize_currency rejects currency codes that are empty after stripping — the field is mandatory and has no default. Raised from model __post_init__ and get_rate.","triggerScenarios":"Passing currency='' or currency='   ' to an entities model constructor or get_rate.","commonSituations":"Blank cells in CSVs feeding model constructors, or empty form fields propagated into the API.","solutions":["Supply a real ISO code like 'USD'","Skip/repair rows with blank currency before constructing models","Add form/API-level required-field validation"],"exampleFix":"# before\nEntityRate(currency=row['ccy'].strip(), ...)\n# after\nEntityRate(currency=row['ccy'].strip() or 'USD', ...)","handlingStrategy":"validation","validationCode":"ccy = (raw or '').strip().upper()\nif not ccy: ccy = 'USD'  # or reject row","typeGuard":null,"tryCatchPattern":"except ValueError as e:\n    if 'cannot be empty' in str(e): default or skip the record","preventionTips":["Treat currency as required in ingestion schemas"],"tags":["validation","currency","empty-value","models"],"backgroundTag":"missing-required-field","analyzedSha":"80ffdda44c5c4db0dd84d70e051cca591cea67df","analyzedAt":"2026-08-28T12:46:38.989Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}