{"record":{"id":"3c75631afe918be2","repo":"HKUDS/Vibe-Trading","slug":"field-name-cannot-contain-whitespace-got-value","errorCode":null,"errorMessage":"{field_name} cannot contain whitespace, got {value!r}","messagePattern":"(.+?) cannot contain whitespace, got (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"agent/src/entities/models.py","lineNumber":91,"sourceCode":"    ``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.\n        field_name: Name used in the error message, for caller context.\n","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/HKUDS/Vibe-Trading/blob/80ffdda44c5c4db0dd84d70e051cca591cea67df/agent/src/entities/models.py#L73-L109","documentation":"normalize_currency uppercases and strips the code but refuses codes containing internal whitespace (e.g. 'US D'), since whitespace indicates a malformed code or a wrong field was passed.","triggerScenarios":"Passing a currency string with embedded whitespace such as 'US D', 'usd ', or accidentally a full label like 'US Dollars' that contains spaces after stripping.","commonSituations":"Passing human-readable currency names instead of codes, or copy-paste artifacts with non-breaking spaces.","solutions":["Pass the ISO alpha-3 code only ('USD'), not a name","Strip/normalize upstream: code.replace('\\xa0','').split()[0] if safe","Map names to codes before constructing models"],"exampleFix":"# before\nEntityRate(currency='US Dollars', ...)\n# after\nEntityRate(currency='USD', ...)","handlingStrategy":"validation","validationCode":"ccy = ''.join(raw.split()).upper()\nassert ' ' not in ccy","typeGuard":"def is_valid_currency(v: str) -> bool:\n    v = v.strip().upper()\n    return len(v) == 3 and v.isalpha()","tryCatchPattern":"except ValueError as e:\n    if 'whitespace' in str(e): map name→ISO code and retry","preventionTips":["Store ISO-4217 alpha-3 codes only","Map labels to codes upstream"],"tags":["validation","currency","whitespace","models"],"backgroundTag":"invalid-argument-value","analyzedSha":"80ffdda44c5c4db0dd84d70e051cca591cea67df","analyzedAt":"2026-08-28T12:46:38.989Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}