{"record":{"id":"dd1be6794f11cfc5","repo":"pentaho/pentaho-kettle","slug":"the-function-call-getfilesize-throw-an-error-dd1be6","errorCode":null,"errorMessage":"The function call getFileSize throw an error : ","messagePattern":"The function call getFileSize 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":2195,"sourceCode":"        }\n        FileObject file = null;\n\n        try {\n          // Source file\n          file = KettleVFS.getInstance( getBowl( actualObject ) ).getFileObject( Context.toString( ArgList[0] ) );\n          long filesize = 0;\n          if ( file.exists() ) {\n            if ( file.getType().equals( FileType.FILE ) ) {\n              filesize = file.getContent().getSize();\n            } else {\n              Context.reportRuntimeError( \"[\" + Context.toString( ArgList[0] ) + \"] is not a file!\" );\n            }\n          } else {\n            Context.reportRuntimeError( \"file [\" + Context.toString( ArgList[0] ) + \"] can not be found!\" );\n          }\n          return filesize;\n        } catch ( IOException e ) {\n          throw Context.reportRuntimeError( \"The function call getFileSize throw an error : \" + e.toString() );\n        } finally {\n          if ( file != null ) {\n            try {\n              file.close();\n            } catch ( Exception e ) {\n              // Ignore close errors\n            }\n          }\n        }\n\n      } else {\n        throw Context.reportRuntimeError( \"The function call getFileSize is not valid.\" );\n      }\n    } catch ( Exception e ) {\n      throw Context.reportRuntimeError( e.toString() );\n    }\n  }\n","sourceCodeStart":2177,"sourceCodeEnd":2213,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java#L2177-L2213","documentation":"getFileSize() throws this when obtaining the file size raises a java.io.IOException; the java exception text is appended to the message. The file existed (the not-found branch was passed) but opening/reading its content or closing the FileObject failed.","triggerScenarios":"getFileSize('/path/file') on an existing path where: the FileObject cannot be read (permission), the size lookup triggers content read that fails, the URI points to a stream-like resource, or close() throws and propagates.","commonSituations":"Special files (device files, named pipes) that fail on read; permission-denied on readable-looking files; flaky network filesystems where metadata access fails.","solutions":["Read the appended java exception text for the actual IO cause.","Check read permissions on the file.","Try converting to a local file:// URL to rule out VFS provider issues.","If the file is on a network share, verify connectivity and retry.","Wrap the call in try/catch in the JS step and default the size to -1."],"exampleFix":"// before\nvar size = getFileSize(path);\n// after\nvar size;\ntry { size = getFileSize(path); } catch (e) { size = -1; }","handlingStrategy":"try-catch","validationCode":"var f = new java.io.File(path);\nif (!f.exists()) { throw new Error('file missing: ' + path); }\nif (!f.canRead()) { throw new Error('not readable: ' + path); }","typeGuard":null,"tryCatchPattern":"try { size = getFileSize(path); } catch (e) { size = -1; Logger.logError('getFileSize failed: ' + e.message); }","preventionTips":["Check existence and readability before calling","Prefer local file:// paths for metadata queries","Retry on transient network filesystem failures","Read the appended java exception text for the cause"],"tags":["javascript","pdi","ioexception","file-size"],"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"}