{"record":{"id":"97088bd41fcd60b5","repo":"prestodb/presto","slug":"file-does-not-exist","errorCode":null,"errorMessage":"File does not exist: ","messagePattern":"File does not exist: ","errorType":"exception","errorClass":"FileNotFoundException","httpStatus":null,"severity":"error","filePath":"presto-hive/src/main/java/com/facebook/presto/hive/s3/PrestoS3FileSystem.java","lineNumber":366,"sourceCode":"            try {\n                return iterator.next();\n            }\n            catch (AmazonClientException e) {\n                throw new IOException(e);\n            }\n        }\n    }\n\n    @Override\n    public FileStatus getFileStatus(Path path)\n            throws IOException\n    {\n        if (path.getName().isEmpty()) {\n            // the bucket root requires special handling\n            if (getS3ObjectMetadata(path).getObjectMetadata() != null) {\n                return new FileStatus(0, true, 1, 0, 0, qualifiedPath(path));\n            }\n            throw new FileNotFoundException(\"File does not exist: \" + path);\n        }\n\n        PrestoS3ObjectMetadata metadata = getS3ObjectMetadata(path);\n\n        if (metadata.getObjectMetadata() == null) {\n            // check if this path is a directory\n            Iterator<LocatedFileStatus> iterator = listPrefix(path, OptionalInt.of(1), ListingMode.SHALLOW_ALL);\n            if (iterator.hasNext()) {\n                return new FileStatus(0, true, 1, 0, 0, qualifiedPath(path));\n            }\n            throw new FileNotFoundException(\"File does not exist: \" + path);\n        }\n\n        return new FileStatus(\n                getObjectSize(path, metadata.getObjectMetadata()),\n                // Some directories (e.g. uploaded through S3 GUI) return a charset in the Content-Type header\n                isDirectory(metadata),\n                1,","sourceCodeStart":348,"sourceCodeEnd":384,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-hive/src/main/java/com/facebook/presto/hive/s3/PrestoS3FileSystem.java#L348-L384","documentation":"PrestoS3FileSystem.getFileStatus throws java.io.FileNotFoundException 'File does not exist: <path>' when the path names the bucket root but getS3ObjectMetadata returns no object metadata (the bucket itself is absent/unnaccessible). Since PrestoS3FileSystem is a Hadoop FileSystem over S3, a missing key/bucket surfaces as the Hadoop-standard FileNotFoundException so callers like listStatus/directory handling can treat it uniformly.","triggerScenarios":"getFileStatus is called (e.g., by directory() during split planning or listStatus) for a path whose S3 HEAD request returns 404: the bucket doesn't exist, the key was deleted, or credentials/IAM policy deny s3:GetObject so S3 answers 403/404.","commonSituations":"Typo in the S3 bucket or path in the table location (s3n/s3a vs s3 scheme mixups); querying a table whose data was deleted by an S3 lifecycle rule; wrong access keys / missing IAM permission causing metadata lookup failure; querying bucket root of a nonexistent bucket.","solutions":["Verify the exact location exists: `aws s3 ls s3://<bucket>/<prefix>/` using the same credentials Presto uses.","Fix the table LOCATION / partition LOCATION in the Hive metastore (MSCK REPAIR TABLE for partitions).","Check IAM policy grants s3:ListBucket and s3:GetObject on the bucket/prefix for the Presto role.","Confirm the URI scheme and path spelling (s3://, s3a://, s3n://) match what the connector expects.","Check for lifecycle/expiration rules that deleted the objects and restore them."],"exampleFix":"// before: partition location points to deleted prefix\nALTER TABLE t ADD PARTITION (ds='2026-01-01') LOCATION 's3://my-bucket/data/ds=2026-01-01/'; -- File does not exist\n// after: verify and correct the location\naws s3 ls s3://my-bucket/data/  # find actual prefix\nALTER TABLE t ADD PARTITION (ds='2026-01-01') LOCATION 's3://my-bucket/data-v2/ds=2026-01-01/';","handlingStrategy":"try-catch","validationCode":"// verify the S3 location with the same credentials before querying\nHeadBucketResponse r = s3.headBucket(b -> b.bucket(bucket)); // throws NoSuchBucketException if absent\nboolean keyExists = s3.listObjectsV2(b -> b.bucket(bucket).prefix(prefix).maxKeys(1)).contents().size() > 0;\nif (!keyExists) throw new IllegalStateException(\"S3 prefix has no objects: \" + bucket + \"/\" + prefix);","typeGuard":"boolean isS3FileNotFound(Throwable t) {\n    return t instanceof FileNotFoundException ||\n        (t instanceof PrestoException && t.getMessage() != null && t.getMessage().startsWith(\"File does not exist:\"));\n}","tryCatchPattern":"try {\n    return query(sql);\n} catch (Exception e) {\n    if (isS3FileNotFound(e)) {\n        // run MSCK REPAIR / fix partition locations, then retry\n        runSql(\"MSCK REPAIR TABLE \" + table);\n        return query(sql);\n    }\n    throw e;\n}","preventionTips":["Verify bucket/prefix spellings and scheme (s3:// vs s3a://) in table and partition locations.","Audit S3 lifecycle/expiration policies against table retention expectations.","Grant the Presto IAM role s3:ListBucket and s3:GetObject on all table prefixes.","Run MSCK REPAIR TABLE after adding/removing S3 partitions."],"tags":["s3","hadoop-filesystem","file-not-found","hive"],"backgroundTag":"s3-file-not-found","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}