{"record":{"id":"6e7f4e4831d9cc77","repo":"pentaho/pentaho-kettle","slug":"unable-to-write-value-to-output-stream","errorCode":null,"errorMessage":"Unable to write value to output stream","messagePattern":"Unable to write value to output stream","errorType":"exception","errorClass":"KettleFileException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/pentaho/di/compatibility/Value.java","lineNumber":1542,"sourceCode":"        default:\n          break; // nothing\n      }\n    }\n  }\n\n  /**\n   * Write the value, including the meta-data to a DataOutputStream\n   *\n   * @param outputStream\n   *          the OutputStream to write to .\n   * @throws KettleFileException\n   *           if something goes wrong.\n   */\n  public void write( OutputStream outputStream ) throws KettleFileException {\n    try {\n      writeObj( new DataOutputStream( outputStream ) );\n    } catch ( Exception e ) {\n      throw new KettleFileException( \"Unable to write value to output stream\", e );\n    }\n  }\n\n  /**\n   * Read the metadata and data for this Value object from the specified data input stream\n   *\n   * @param dis\n   * @throws IOException\n   */\n  public void readObj( DataInputStream dis ) throws IOException {\n    // type\n    int theType = dis.readInt();\n    newValue( theType );\n\n    // name-length\n    int nameLength = dis.readInt();\n\n    // name","sourceCodeStart":1524,"sourceCodeEnd":1560,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/core/src/main/java/org/pentaho/di/compatibility/Value.java#L1524-L1560","documentation":"substr accepts only the 2-argument (start) and 3-argument (start, length) forms. This argument-count guard at ScriptValuesAddedFunctions.java:1703 throws when ArgList.length is anything other than 2 or 3. The message mirrors JavaScript's flexibility expectations but the Kettle implementation is strict.","triggerScenarios":"Calling substr() with zero or one argument, or with 4+ arguments such as substr(str, start, len, extra).","commonSituations":"Forgetting the mandatory start argument (native JS substr requires only length optionally); passing extra options; calling with only a string expecting the whole-string default.","solutions":["Always pass a start index: substr(str, 0) to get the whole string.","Remove any extra arguments beyond start and length.","Use native JavaScript slice for flexible/omittable arguments."],"exampleFix":"// before\nsubstr(str); // missing start\n// after\nsubstr(str, 0);","handlingStrategy":"validation","validationCode":"if (arguments.length < 2 || arguments.length > 3) throw new Error(\"substr requires start (and optional length)\");","typeGuard":"null","tryCatchPattern":"var r;\ntry {\n  r = substr(String(str == null ? \"\" : str), 0);\n} catch (e) {\n  r = \"\";\n}","preventionTips":["Always supply a start index - it is mandatory","Pass at most 3 arguments","Use native slice() when you need omittable arguments"],"tags":["javascript","argument-count","string-processing","scripting"],"backgroundTag":"missing-required-argument","analyzedSha":"f3058517a153da500bf4551f46d79b91bf8ec552","analyzedAt":"2026-09-13T14:04:16.340Z","contentChangedAt":"2026-09-13T14:04:16.340Z","schemaVersion":2},"datasetVersion":"2026-09-20T23:17:15.980Z"}