{"id":"8d2f192b17204937","repo":"apache/kafka","slug":"this-field-cannot-be-empty","errorCode":null,"errorMessage":"This field cannot be empty","messagePattern":"This field cannot be empty","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"warning","filePath":"docker/common.py","lineNumber":30,"sourceCode":"# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport subprocess\nimport tempfile\nimport os\nimport shutil\n\ndef execute(command):\n    if subprocess.run(command).returncode != 0:\n        raise SystemError(\"Failure in executing following command:- \", \" \".join(command))\n\ndef get_input(message):\n    value = input(message)\n    if value == \"\":\n        raise ValueError(\"This field cannot be empty\")\n    return value\n\ndef build_docker_image_runner(command, image_type, kafka_archive=None):\n    temp_dir_path = tempfile.mkdtemp()\n    current_dir = os.path.dirname(os.path.realpath(__file__))\n    shutil.copytree(f\"{current_dir}/{image_type}\", f\"{temp_dir_path}/{image_type}\", dirs_exist_ok=True)\n    shutil.copytree(f\"{current_dir}/resources\", f\"{temp_dir_path}/{image_type}/resources\", dirs_exist_ok=True)\n    shutil.copy(f\"{current_dir}/server.properties\", f\"{temp_dir_path}/{image_type}\")\n    if kafka_archive:\n        shutil.copy(kafka_archive, f\"{temp_dir_path}/{image_type}/kafka.tgz\")\n    command = command.replace(\"$DOCKER_FILE\", f\"{temp_dir_path}/{image_type}/Dockerfile\")\n    command = command.replace(\"$DOCKER_DIR\", f\"{temp_dir_path}/{image_type}\")\n    try:\n        execute(command.split())\n    except:\n        raise SystemError(\"Docker Image Build failed\")\n    finally:\n        shutil.rmtree(temp_dir_path)","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/apache/kafka/blob/c31c9215e131f8c17e79f8901b48c13ee6aa8e7a/docker/common.py#L12-L48","documentation":"Raised by docker/common.get_input() when the user presses Enter without typing anything at the input() prompt. get_input() is the interactive prompt wrapper used by the docker release/build helper scripts to collect required values (image name, kafka url, image type, etc.). An empty answer is treated as an invalid required field rather than silently proceeding.","triggerScenarios":"Calling get_input(message) and responding with an empty string (just Enter) at the interactive prompt.","commonSituations":"User skipped a required prompt by accident, hit Enter to accept a default that doesn't exist, ran the script non-interactively (piped empty stdin) so all prompts read empty, or terminal sent an unexpected newline.","solutions":["Provide a non-empty value at the prompt.","If running non-interactively, feed values via stdin or switch to argparse/CLI flags (as docker_release.py already does) instead of prompts.","If the value should be optional, modify the caller to pass a default instead of relying on get_input."],"exampleFix":"# before\nimage = get_input(\"Docker image: \")  # user hits Enter\n# after\nimage = get_input(\"Docker image: \")  # user types apache/kafka:latest\n# or run with CLI flags: ./docker_release.py apache/kafka:latest --image-type jvm","handlingStrategy":"validation","validationCode":"# Strip whitespace and reject empty input before it reaches get_input().\nvalue = input(message).strip()\nif not value:\n    raise ValueError(\"This field cannot be empty\")","typeGuard":"# Treat None and blank strings as invalid for required interactive fields.\ndef is_non_empty_str(v) -> bool:\n    return isinstance(v, str) and v.strip() != \"\"","tryCatchPattern":"from common import get_input\ntry:\n    value = get_input(message)\nexcept ValueError:\n    # Re-prompt the user instead of crashing the release flow.\n    value = get_input(message + \" (required): \")","preventionTips":["Use argparse with required=True for CLI args instead of interactive prompts wherever possible.","Pre-validate interactive input with .strip() so whitespace-only answers are rejected.","Provide a --non-interactive mode that reads from env vars or a config file for CI."],"tags":["python","cli","input-validation","docker","ux"],"analyzedSha":"c31c9215e131f8c17e79f8901b48c13ee6aa8e7a","analyzedAt":"2026-08-03T12:34:05.770Z","schemaVersion":2}