{"record":{"id":"099b6f436a53a248","repo":"pentaho/pentaho-kettle","slug":"the-function-call-getfileextension-throw-an-error","errorCode":null,"errorMessage":"The function call getFileExtension throw an error : ","messagePattern":"The function call getFileExtension throw an error : ","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java","lineNumber":2363,"sourceCode":"        if ( ArgList[0].equals( null ) ) {\n          return null;\n        }\n        FileObject file = null;\n\n        try {\n          // Source file\n          file = KettleVFS.getInstance( getBowl( actualObject ) ).getFileObject( Context.toString( ArgList[0] ) );\n          String Extension = null;\n          if ( file.exists() ) {\n            Extension = file.getName().getExtension().toString();\n\n          } else {\n            Context.reportRuntimeError( \"file [\" + Context.toString( ArgList[0] ) + \"] can not be found!\" );\n          }\n\n          return Extension;\n        } catch ( IOException e ) {\n          throw Context.reportRuntimeError( \"The function call getFileExtension throw an error : \" + e.toString() );\n        } finally {\n          if ( file != null ) {\n            try {\n              file.close();\n            } catch ( Exception e ) {\n              // Ignore errors\n            }\n          }\n        }\n\n      } else {\n        throw Context.reportRuntimeError( \"The function call getFileExtension is not valid.\" );\n      }\n    } catch ( Exception e ) {\n      throw Context.reportRuntimeError( e.toString() );\n    }\n  }\n","sourceCodeStart":2345,"sourceCodeEnd":2381,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java#L2345-L2381","documentation":"getFileExtension() returns the extension of the file given as its argument, resolved through KettleVFS. When a java.io.IOException occurs during VFS resolution or name parsing, the function rethrows it as a JavaScript runtime error prefixed 'The function call getFileExtension throw an error : '. It signals an I/O failure, not an argument problem.","triggerScenarios":"IOException from KettleVFS.getFileObject(path) or while inspecting the resolved FileObject — bad URI, unsupported scheme, unreachable remote filesystem, resolution/close I/O failures.","commonSituations":"Network drives or SFTP servers offline, invalid URI characters in the path, missing commons-vfs provider for the scheme, repository/relative path that cannot be resolved in the environment.","solutions":["Use a correct, fully-qualified VFS URI with special characters escaped","Check connectivity/credentials to the remote filesystem","Verify the scheme is supported by the deployed commons-vfs providers","Pre-check existence with isFile()/isFolder() to localize the failure"],"exampleFix":"// before\nvar ext = getFileExtension('C:\\\\data\\\\report.txt'); // unescaped backslashes on URI parse\n// after\nvar ext = getFileExtension('file:///C:/data/report.txt');","handlingStrategy":"try-catch","validationCode":"var f = isFile(path); // resolve failures surface here first","typeGuard":"function looksLikeUri(v) { return typeof v === 'string' && /^[a-zA-Z][a-zA-Z0-9+.-]*:\\/.\\//.test(v); }","tryCatchPattern":"try { var ext = getFileExtension(path); } catch (e) {\n  ext = ''; // VFS IOException — fall back to parsing the string\n  ext = path && path.lastIndexOf('.') >= 0 ? path.substring(path.lastIndexOf('.') + 1) : '';\n}","preventionTips":["Prefer file:// URIs for local paths to avoid platform quirks","URL-encode paths with spaces or unicode","Confirm the scheme's provider is on the classpath","Pre-check file existence before metadata extraction"],"tags":["io","vfs","filesystem"],"backgroundTag":"file-read-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"}