{"record":{"id":"ac489a4888960eef","repo":"langflow-ai/langflow","slug":"code-must-be-a-non-empty-string","errorCode":null,"errorMessage":"code must be a non-empty string","messagePattern":"code must be a non-empty string","errorType":"validation","errorClass":"UserComponentError","httpStatus":null,"severity":"error","filePath":"src/backend/base/langflow/agentic/services/user_components.py","lineNumber":239,"sourceCode":"    if err := _check_windows_portability(class_name):\n        raise UserComponentError(err)\n    # Reject `.`, `..`, leading dots, leading underscores, dunders, and\n    # anything that isn't a valid CamelCase identifier.\n    if not _CLASS_NAME_RE.fullmatch(class_name):\n        msg = (\n            f\"class_name must be a CamelCase identifier \"\n            f\"(letters/digits/underscores, leading uppercase). Got: {class_name!r}\"\n        )\n        raise UserComponentError(msg)\n    if class_name.upper() in _WINDOWS_RESERVED_DEVICES:\n        msg = f\"class_name {class_name!r} is a Windows-reserved device name\"\n        raise UserComponentError(msg)\n\n\ndef _validate_code(code: str) -> None:\n    if not code or not code.strip():\n        msg = \"code must be a non-empty string\"\n        raise UserComponentError(msg)\n    encoded_size = len(code.encode(\"utf-8\"))\n    if encoded_size > MAX_COMPONENT_SOURCE_BYTES:\n        msg = f\"code size {encoded_size} bytes exceeds limit of {MAX_COMPONENT_SOURCE_BYTES} bytes\"\n        raise UserComponentError(msg)\n\n\ndef _resolve_components_dir(*, user_id: str | None) -> Path:\n    \"\"\"Resolve and create ``<sandbox>/.components/`` for the given user.\n\n    Reuses the FS tool's authoritative sandbox resolver so the hash\n    function, pepper handling, AUTO_LOGIN dispatch, and no-user refusal\n    stay in one place. The reserved-segment guard does NOT apply here —\n    this helper is the privileged writer that the guard is protecting.\n    \"\"\"\n    component = FileSystemToolComponent()\n    if user_id is not None:\n        component._user_id = user_id  # noqa: SLF001 — privileged binding seam\n    try:","sourceCodeStart":221,"sourceCodeEnd":257,"githubUrl":"https://github.com/langflow-ai/langflow/blob/976ec789d2886a86de109c044d089d68e96c9a35/src/backend/base/langflow/agentic/services/user_components.py#L221-L257","documentation":"Raised by _validate_code when the component source code is None-equivalent, empty, or only whitespace. A .components/<ClassName>.py file with no code would produce a broken module for the registry overlay to import, so registration is refused up front.","triggerScenarios":"Calling register_user_component with code='', code='   \\n', or passing None; typically from an orchestrator wiring mistake where the streamed code buffer was never filled before the registration hook fired.","commonSituations":"Streaming loop registering the component before the code finished accumulating; a generation step returned an empty string (model refusal or truncation at the seam) and the caller did not check it.","solutions":["Check the generated code is non-empty (code and code.strip()) before calling register_user_component.","If code arrived empty from the model, retry generation instead of registering.","Prefer register_user_component_if_valid, which swallows this input refusal and returns None."],"exampleFix":"# before\nregister_user_component(user_id=uid, class_name=\"MyTool\", code=generated)  # generated == \"\"\n\n# after\nif generated and generated.strip():\n    register_user_component(user_id=uid, class_name=\"MyTool\", code=generated)","handlingStrategy":"validation","validationCode":"def has_component_code(code: str | None) -> bool:\n    return isinstance(code, str) and bool(code.strip())","typeGuard":"def is_nonempty_source(code: str | None) -> TypeGuard[str]:\n    return isinstance(code, str) and len(code.strip()) > 0","tryCatchPattern":"try:\n    register_user_component(user_id=uid, class_name=name, code=code)\nexcept UserComponentError as e:\n    if \"non-empty\" in str(e):\n        skip_registration()  # regenerate instead of registering","preventionTips":["Gate the registration hook on a non-empty, stripped code buffer.","Use register_user_component_if_valid when best-effort behavior is acceptable — it swallows input refusals and returns None."],"tags":["validation","empty-input","user-components"],"backgroundTag":null,"analyzedSha":"976ec789d2886a86de109c044d089d68e96c9a35","analyzedAt":"2026-08-14T18:23:12.227Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}