{"record":{"id":"0d3d12eb1c7fda1c","repo":"pentaho/pentaho-kettle","slug":"jsonoutput-error-opennewfile","errorCode":"JsonOutput.Error.OpenNewFile","errorMessage":"JsonOutput.Error.OpenNewFile","messagePattern":"JsonOutput\\.Error\\.OpenNewFile","errorType":"exception","errorClass":"KettleStepException","httpStatus":null,"severity":"error","filePath":"plugins/json/core/src/main/java/org/pentaho/di/trans/steps/jsonoutput/JsonOutput.java","lineNumber":244,"sourceCode":"    String value;\n    if ( data.realBlocName == \"\" ) {\n      value = data.ja.toJSONString();\n    } else {\n      data.jg.put( data.realBlocName, data.ja );\n      value = data.jg.toJSONString();\n    }\n\n\n    if ( data.outputValue && data.outputRowMeta != null ) {\n      Object[] outputRowData = RowDataUtil.addValueData( rowData, data.inputRowMetaSize, value );\n      incrementLinesOutput();\n      putRow( data.outputRowMeta, outputRowData );\n    }\n\n    if ( data.writeToFile && !data.ja.isEmpty() ) {\n      // Open a file\n      if ( !openNewFile() ) {\n        throw new KettleStepException( BaseMessages.getString(\n          PKG, \"JsonOutput.Error.OpenNewFile\", buildFilename() ) );\n      }\n      // Write data to file\n      try {\n        data.writer.write( value );\n      } catch ( Exception e ) {\n        throw new KettleStepException( BaseMessages.getString( PKG, \"JsonOutput.Error.Writing\" ), e );\n      }\n      // Close file\n      closeFile();\n    }\n    // Data are safe\n    data.rowsAreSafe = true;\n    data.ja = new JSONArray();\n  }\n\n  public boolean init( StepMetaInterface smi, StepDataInterface sdi ) {\n    meta = (JsonOutputMeta) smi;","sourceCodeStart":226,"sourceCodeEnd":262,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/plugins/json/core/src/main/java/org/pentaho/di/trans/steps/jsonoutput/JsonOutput.java#L226-L262","documentation":"In JsonOutput.outPutRow, when the step is configured to write to a file and the accumulated JSON array is non-empty, it calls openNewFile(); if that returns false it throws JsonOutput.Error.OpenNewFile including the built filename. This means the step could not open/create the target file for writing.","triggerScenarios":"data.writeToFile is true, data.ja is non-empty, and openNewFile() returns false — typically because the path is invalid, the directory doesn't exist, the file is locked by another process, or permissions deny writing.","commonSituations":"Output filename points to a non-existent or read-only directory; file already open in another program (e.g. Excel/editor lock on Windows); relative path resolved differently because the transformation runs from a different working directory or on a server; filename with environment variables not substituted.","solutions":["Check the output filename in the step dialog; make sure the parent directory exists and the process user has write permission.","Use fully qualified paths or ${Internal.Transformation.Filename.Directory} variables instead of relative paths.","Verify environment variables in the filename resolve correctly (log the result of buildFilename()).","Close any program locking the target file, or write to a unique filename (include date/time variables).","Run the transformation as a user with sufficient filesystem permissions on the server/agent."],"exampleFix":"// before (filename relative to unknown CWD)\n${USER_DIR}/output.json\n// after\n${Internal.Transformation.Filename.Directory}/output.json","handlingStrategy":"try-catch","validationCode":"// Pre-flight check in the job before the transformation\nFile outDir = new File(\"/data/output\");\nif (!outDir.canWrite()) throw new IllegalStateException(\"Output dir not writable: \" + outDir);","typeGuard":null,"tryCatchPattern":"try { transformation.execute(...); } catch (KettleStepException e) {\n  if (e.getMessage().contains(\"JsonOutput.Error.OpenNewFile\")) {\n    // parse filename from message, check existence/permissions, alert operator\n  }\n  throw e;\n}","preventionTips":["Pre-create output directories with correct ownership in deployment scripts.","Use absolute paths anchored on transformation-location variables, not CWD-relative ones.","Include timestamp variables in filenames to avoid locks on a shared static filename.","Verify permissions of the service account running PDI/kitchen on the output volume."],"tags":["pdi","file-io","permissions","kettle","json-output"],"backgroundTag":"file-open-failed","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"}