{"record":{"id":"cc7e04e68864b773","repo":"D4Vinci/Scrapling","slug":"invalid-argument-type-e","errorCode":null,"errorMessage":"Invalid argument type: {e}","messagePattern":"Invalid argument type: (.+?)","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"scrapling/engines/_browsers/_validators.py","lineNumber":252,"sourceCode":"    defaults = models_default_values[model]\n    return {k: v for k, v in params.items() if k not in defaults or v != defaults[k]}\n\n\n@overload\ndef validate(params: Dict, model: type[StealthConfig]) -> StealthConfig: ...\n\n\n@overload\ndef validate(params: Dict, model: type[PlaywrightConfig]) -> PlaywrightConfig: ...\n\n\ndef validate(params: Dict, model: type[PlaywrightConfig] | type[StealthConfig]) -> PlaywrightConfig | StealthConfig:\n    try:\n        # Filter out params with the default values (no need to validate them) to speed up validation\n        filtered = _filter_defaults(params, model.__name__)\n        return convert(filtered, model)\n    except ValidationError as e:\n        raise TypeError(f\"Invalid argument type: {e}\") from e\n","sourceCodeStart":234,"sourceCodeEnd":253,"githubUrl":"https://github.com/D4Vinci/Scrapling/blob/5d213a2d4764002bfc4fed33c32fe09fa8b0bf7f/scrapling/engines/_browsers/_validators.py#L234-L253","documentation":"validate() converts msgspec ValidationError into TypeError('Invalid argument type: ...') whenever kwargs passed to a session constructor or fetch() do not match the config Struct's types. The chained msgspec message names the exact offending field and expected type, so read the full exception text.","triggerScenarios":"Passing headless='yes' (string instead of bool), cookies='a=b' (string instead of a list of cookie dicts), max_pages='3' (string), unknown-typed proxy values, or any kwarg whose declared type in PlaywrightConfig/StealthConfig mismatches — including constraint violations like max_pages=0 (must be 1..50) or retries=20 (must be 1..10).","commonSituations":"Loading config from JSON/YAML/ENV where everything arrives as strings; passing Python primitives where msgspec Structs/typed sequences are required; boundary constraint violations (max_pages, retries, retry_delay).","solutions":["Read the appended msgspec message in the traceback — it names the field, expected type, and constraint that failed","Coerce config values before passing: int()/bool()/proper dict structures, especially values loaded from files/ENV","Check field constraints: max_pages 1-50, retries 1-10, retry_delay >= 0, wait_selector_state in the allowed states"],"exampleFix":"# before (config loaded from JSON, all strings)\nsession = StealthySession(headless='true', max_pages='3', cookies='session=abc')\n\n# after\ncfg = json.load(open('config.json'))\nsession = StealthySession(\n    headless=bool(cfg['headless']),\n    max_pages=int(cfg['max_pages']),\n    cookies=[{'name': 'session', 'value': 'abc', 'domain': 'example.com', 'path': '/'}],\n)","handlingStrategy":"try-catch","validationCode":"# coerce before constructing the session\ndef sanitize(cfg: dict) -> dict:\n    if 'headless' in cfg: cfg['headless'] = bool(cfg['headless'])\n    if 'max_pages' in cfg: cfg['max_pages'] = int(cfg['max_pages'])\n    if 'retries' in cfg: cfg['retries'] = int(cfg['retries'])\n    assert 1 <= cfg.get('max_pages', 1) <= 50\n    assert 1 <= cfg.get('retries', 3) <= 10\n    return cfg","typeGuard":"def kwargs_match_config(cfg: dict) -> bool:\n    try:\n        convert({k: v for k, v in cfg.items()}, StealthConfig)\n        return True\n    except ValidationError:\n        return False","tryCatchPattern":"from msgspec import ValidationError\ntry:\n    session = StealthySession(**cfg)\nexcept TypeError as e:\n    if 'Invalid argument type' in str(e):\n        # e.__cause__ carries msgspec's field-level detail\n        log.error('config type error: %s', e.__cause__)\n        raise\n    raise","preventionTips":["Coerce values from JSON/YAML/ENV (strings by default) with int()/bool()/dict() before passing","Read the chained msgspec ValidationError — it names the exact field and expected type","Respect constraints: max_pages 1-50, retries 1-10, retry_delay >= 0","Dry-run configs through msgspec.convert at startup to fail fast"],"tags":["validation","typeerror","msgspec","config","type-coercion"],"backgroundTag":null,"analyzedSha":"5d213a2d4764002bfc4fed33c32fe09fa8b0bf7f","analyzedAt":"2026-08-14T22:23:09.440Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}