{"record":{"id":"9fa8b7e2e5d0eaac","repo":"pentaho/pentaho-kettle","slug":"the-function-call-deletefile-is-not-valid-9fa8b7","errorCode":null,"errorMessage":"The function call deleteFile is not valid.","messagePattern":"The function call deleteFile is not valid\\.","errorType":"exception","errorClass":"RhinoRuntimeError","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java","lineNumber":2058,"sourceCode":"        // Object act = actualObject.get(\"_step_\", actualObject);\n        // ScriptValuesMod act = (ScriptValuesMod)Context.toType(scm_delete, ScriptValuesMod.class);\n\n        FileObject fileObject = null;\n\n        try {\n          fileObject = KettleVFS.getInstance( getBowl( actualObject ) ).getFileObject( Context.toString( ArgList[0] ) );\n          if ( fileObject.exists() ) {\n            if ( fileObject.getType() == FileType.FILE ) {\n              if ( !fileObject.delete() ) {\n                Context.reportRuntimeError( \"We can not delete file [\" + Context.toString( ArgList[0] ) + \"]!\" );\n              }\n            }\n\n          } else {\n            Context.reportRuntimeError( \"file [\" + Context.toString( ArgList[0] ) + \"] can not be found!\" );\n          }\n        } catch ( IOException e ) {\n          throw Context.reportRuntimeError( \"The function call deleteFile is not valid.\" );\n        } finally {\n          if ( fileObject != null ) {\n            try {\n              fileObject.close();\n            } catch ( Exception e ) {\n              // Ignore errors\n            }\n          }\n        }\n\n      } else {\n        throw Context.reportRuntimeError( \"The function call deleteFile is not valid.\" );\n      }\n    } catch ( Exception e ) {\n      throw Context.reportRuntimeError( e.toString() );\n    }\n  }\n","sourceCodeStart":2040,"sourceCodeEnd":2076,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java#L2040-L2076","documentation":"deleteFile(path) attempts to delete a file through VFS; when an IOException occurs during the delete operation the implementation throws this Rhino runtime error stating the function call is not valid. The original IOException detail is not included, so the message appears even for ordinary I/O failures like locked or missing files.","triggerScenarios":"deleteFile('path') throwing IOException during the delete: file locked by another process, no write permission on the directory, VFS provider failing, or the file disappearing between the existence check and delete.","commonSituations":"Deleting a file still held open by a writer on Windows; running under a user without permissions; network/FTP VFS paths temporarily unreachable; race where another step deleted the file first.","solutions":["Check the file isn't locked/open by another process or step before deleting.","Verify the user running the transformation has write permission on the file's directory.","Confirm the path and VFS scheme are correct (e.g. file:/// vs sftp://) and reachable.","Check the file still exists right before deletion to avoid race conditions.","Catch the error in the JS script and log/handle it instead of failing the step."],"exampleFix":"// before\ndeleteFile('/data/out.csv'); // fails if file is locked\n// after\ntry {\n  deleteFile('/data/out.csv');\n} catch (e) {\n  // log and continue or retry later\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { deleteFile(path); } catch (e) { if (String(e).indexOf('deleteFile is not valid') >= 0) { logError('Could not delete ' + path + ' - file may be locked or permission denied'); } else { throw e; } }","preventionTips":["Close files/writers before deleting.","Run the transformation with sufficient OS permissions.","Verify VFS path scheme and connectivity before delete.","Handle delete failures in-script rather than letting the step fail."],"tags":["file-io","ioexception","javascript","pentaho"],"backgroundTag":"file-delete-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"}