{"record":{"id":"d3c53a8daf480b2e","repo":"pentaho/pentaho-kettle","slug":"the-function-call-getfileextension-is-not-valid-d3c53a","errorCode":null,"errorMessage":"The function call getFileExtension is not valid.","messagePattern":"The function call getFileExtension is not valid\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java","lineNumber":2375,"sourceCode":"          } 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\n  public static String getParentFoldername( Context actualContext, Scriptable actualObject, Object[] ArgList,\n    Function FunctionContext ) {\n    try {\n      if ( ArgList.length == 1 && !isNull( ArgList[0] ) && !isUndefined( ArgList[0] ) ) {\n        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] ) );","sourceCodeStart":2357,"sourceCodeEnd":2393,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java#L2357-L2393","documentation":"getFileExtension() is a JavaScript function added by PDI's ScriptValuesMod step. It validates its argument list before performing any VFS work; if it is not called with exactly one non-null, non-undefined argument it throws 'The function call getFileExtension is not valid.' as a JavaScript runtime error, aborting the script execution for that row.","triggerScenarios":"Call with zero or multiple arguments, or with a first argument that is null or undefined (guard: ArgList.length == 1 && !isNull && !isUndefined).","commonSituations":"Filename field missing from the row stream, JavaScript variable name typo, null value produced by an earlier step, or copied code calling with wrong arity.","solutions":["Call getFileExtension with exactly one argument","Null/undefined-check the argument variable first","Ensure the upstream step populates the filename field","Handle the error in a try/catch and return a default extension"],"exampleFix":"// before\nvar e = getFileExtension(fname, true);\n// after\nvar e = (fname != null) ? getFileExtension(fname) : '';","handlingStrategy":"validation","validationCode":"if (typeof fname === 'undefined' || fname === null || fname === '') {\n  throw new Error('getFileExtension requires a non-empty path');\n}\nvar e = getFileExtension(fname);","typeGuard":"function isStr(v) { return typeof v === 'string'; }","tryCatchPattern":"try { var e = getFileExtension(fname); } catch (e) { e = ''; }","preventionTips":["Verify field names referenced in scripts exist upstream","Null-handling steps before script steps","Keep call arity exact","Add script-level try/catch for row-level resilience"],"tags":["javascript","argument-count","kettle"],"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"}