{"record":{"id":"d75955437f8a6f05","repo":"pentaho/pentaho-kettle","slug":"the-function-call-deletefile-is-not-valid","errorCode":null,"errorMessage":"The function call deleteFile is not valid.","messagePattern":"The function call deleteFile is not valid\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java","lineNumber":1970,"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( bowl ).getFileObject( (String) ArgList[0] );\n          if ( fileObject.exists() ) {\n            if ( fileObject.getType() == FileType.FILE ) {\n              if ( !fileObject.delete() ) {\n                throw new RuntimeException( \"We can not delete file [\" + (String) ArgList[0] + \"]!\" );\n              }\n            }\n\n          } else {\n            throw new RuntimeException( \"file [\" + ArgList[0] + \"] can not be found!\" );\n          }\n        } catch ( IOException e ) {\n          throw new RuntimeException( \"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 new RuntimeException( \"The function call deleteFile is not valid.\" );\n      }\n    } catch ( Exception e ) {\n      throw new RuntimeException( e.toString() );\n    }\n  }\n","sourceCodeStart":1952,"sourceCodeEnd":1988,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java#L1952-L1988","documentation":"Inside deleteFile(), any IOException raised while resolving or inspecting the file object is swallowed and replaced with the generic message 'The function call deleteFile is not valid.' This indicates the VFS/IO layer failed (bad URI, unsupported scheme, connection error) rather than the file simply not existing.","triggerScenarios":"Calling deleteFile() with a malformed VFS URI or unsupported scheme (the KettleVFS.getFileObject call throws IOException), or an IO error while calling exists()/type checks.","commonSituations":"Passing a Windows path with backslashes or drive letters that VFS cannot parse; using schemes like sftp:/ with missing/invalid connection config; typos in the URI (e.g. 'htp://'); special characters in the filename that break URI parsing.","solutions":["Wrap the raw RuntimeException in a try-catch in your script and log the underlying cause — this throw discards the original IOException, so reproduce the path with KettleVFS directly for a real message.","Validate the path is a well-formed VFS URI (correct scheme, forward slashes, no illegal characters) before calling.","Test the same path with a 'Text File Input' step or KettleVFS in a small script to see the true IOException.","Prefer java.io.File/java.nio.file.Files for plain local paths instead of deleteFile() to get clearer errors."],"exampleFix":"// before\ndeleteFile('C:\\\\data\\\\out.txt'); // backslashes break VFS URI\n// after\ndeleteFile('file:///C:/data/out.txt');","handlingStrategy":"type-guard","validationCode":"// reject paths VFS cannot parse before calling\nif (!/^[a-z]+:\\/\\//.test(path) && path.indexOf('\\\\') >= 0) { throw new Error('normalize path first'); }","typeGuard":"function isVfsUri(p) { return typeof p === 'string' && (/^[a-z]+:\\/\\//.test(p) || p.startsWith('/')); }","tryCatchPattern":"try { deleteFile(path); } catch (e) { // message hides the real IOException; retry path via java.io.File to diagnose\n  var f = new java.io.File(path); if (!f.delete()) throw new Error('delete failed: ' + path); }","preventionTips":["Use forward slashes and proper schemes in paths","Validate URIs before calling VFS-backed helpers","For local files prefer java.nio APIs with clearer errors"],"tags":["file-io","io-exception","vfs","uri"],"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"}