{"record":{"id":"dead7798fb38dd2d","repo":"apache/flink","slug":"a-user-provided-generator-function-threw-an-except","errorCode":null,"errorMessage":"A user-provided generator function threw an exception on this input: %s","messagePattern":"A user-provided generator function threw an exception on this input: (.+?)","errorType":"exception","errorClass":"FlinkRuntimeException","httpStatus":null,"severity":"error","filePath":"flink-connectors/flink-connector-datagen/src/main/java/org/apache/flink/connector/datagen/source/DoubleEmittingSourceReaderWithCheckpointsInBetween.java","lineNumber":155,"sourceCode":"        }\n\n        if (allowedToExit != null) {\n            if (allowedToExit.getAsBoolean()) {\n                availability.complete(null);\n            }\n        }\n    }\n\n    @Override\n    protected O convert(E value) {\n        try {\n            return generatorFunction.map(value);\n        } catch (Exception e) {\n            String message =\n                    String.format(\n                            \"A user-provided generator function threw an exception on this input: %s\",\n                            value.toString());\n            throw new FlinkRuntimeException(message, e);\n        }\n    }\n}\n","sourceCodeStart":137,"sourceCodeEnd":159,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-connectors/flink-connector-datagen/src/main/java/org/apache/flink/connector/datagen/source/DoubleEmittingSourceReaderWithCheckpointsInBetween.java#L137-L159","documentation":"Thrown by convert() in DoubleEmittingSourceReaderWithCheckpointsInBetween when generatorFunction.map(value) throws any exception. The message uses String.format to include the toString() of the specific input value that caused the failure, and the original exception is wrapped in FlinkRuntimeException.","triggerScenarios":"The user-provided GeneratorFunction's map() method throws on a specific input value. Causes include NPE, arithmetic errors, business logic exceptions, class cast failures, or unhandled edge cases in the mapping logic.","commonSituations":"Generator function that does not handle null fields in the input; index out of bounds in a lookup function; type cast failure; division by zero or other arithmetic error on specific input.","solutions":["Inspect the input value in the error message to identify the problematic data.","Add input validation and null-checks in the GeneratorFunction.map() method.","Add try-catch in map() for known edge cases, returning a default or filtered value.","Fix the root cause in the mapping logic for the failing input."],"exampleFix":"// before: map() throws NPE on null field\nGeneratorFunction<Long, String> fn = index -> records.get(index).getName().toUpperCase();\n\n// after: guard against null\nGeneratorFunction<Long, String> fn = index -> {\n    String name = records.get(index).getName();\n    return name != null ? name.toUpperCase() : \"UNKNOWN\";\n};","handlingStrategy":"try-catch","validationCode":"// Validate map() handles all known inputs before using the source\nGeneratorFunction<E, O> fn = ...;\nfor (E testInput : testInputs) {\n    fn.map(testInput); // should not throw for valid inputs\n}","typeGuard":null,"tryCatchPattern":"try {\n    sourceReader.pollNext(output);\n} catch (FlinkRuntimeException e) {\n    if (e.getMessage().startsWith(\"A user-provided generator function threw\")) {\n        // extract the failing input value from the message, fix the map() logic\n    }\n    throw e;\n}","preventionTips":["Add null-checks and input validation in GeneratorFunction.map().","Unit-test map() with edge-case inputs (null fields, empty strings, boundary values).","Handle known exceptions inside map() with defaults or filtering."],"tags":["datagen","generator-function","user-code","runtime","test"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}