{"record":{"id":"654674d3f7fa5301","repo":"apache/beam","slug":"can-t-read-private-key-from-provided-path","errorCode":null,"errorMessage":"Can't read private key from provided path","messagePattern":"Can't read private key from provided path","errorType":"exception","errorClass":"java.lang.RuntimeException","httpStatus":null,"severity":"error","filePath":"sdks/java/io/snowflake/src/main/java/org/apache/beam/sdk/io/snowflake/KeyPairUtils.java","lineNumber":147,"sourceCode":"        throw new RuntimeException(\n            \"Invalid type of PEM file: \"\n                + pemObject.getType()\n                + \". Supported types: \"\n                + ENCRYPTED_PRIVATE_KEY\n                + \", \"\n                + UNENCRYPTED_PRIVATE_KEY);\n      }\n    } catch (IOException e) {\n      throw new RuntimeException(\"Can't read parse private key\");\n    }\n  }\n\n  public static String readPrivateKeyFile(String privateKeyPath) {\n    try {\n      byte[] keyBytes = Files.readAllBytes(Paths.get(privateKeyPath));\n      return new String(keyBytes, StandardCharsets.UTF_8);\n    } catch (IOException e) {\n      throw new RuntimeException(\"Can't read private key from provided path\");\n    }\n  }\n}\n","sourceCodeStart":129,"sourceCodeEnd":151,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/io/snowflake/src/main/java/org/apache/beam/sdk/io/snowflake/KeyPairUtils.java#L129-L151","documentation":"readPrivateKeyFile loads the raw bytes of a private key file and returns them as a UTF-8 string. When Files.readAllBytes throws IOException (file missing, unreadable, is a directory), it throws RuntimeException('Can't read private key from provided path').","triggerScenarios":"Calling KeyPairUtils.readPrivateKeyFile(path) (or the SnowflakeIO .withPrivateKeyFile/reads path) with a path that does not exist, points to a directory, or is not readable by the process.","commonSituations":"Typo in the key path in pipeline options; key not distributed to Beam workers; running in a container image that doesn't include the key; path uses Windows backslashes on Linux workers.","solutions":["Check that the path is correct and absolute; test with a quick Files.exists(path) or ls on the runner.","Ensure the key file is staged with the job (container image, --filesToStage, or a GCS/URL location supported by SnowflakeIO).","Fix read permissions on the file for the user running the pipeline.","Wrap the call yourself to include the path in the message: read the bytes first with Files.readAllBytes and produce a clearer error."],"exampleFix":"// before\nString key = KeyPairUtils.readPrivateKeyFile(\"~/.snowflake/key.p8\"); // '~' not expanded by Java\n// after\nString key = KeyPairUtils.readPrivateKeyFile(System.getProperty(\"user.home\") + \"/.snowflake/key.p8\");","handlingStrategy":"try-catch","validationCode":"java.nio.file.Path p = java.nio.file.Paths.get(path);\nif (!java.nio.file.Files.exists(p)) throw new IllegalArgumentException(\"Key file not found: \" + p);\nif (!java.nio.file.Files.isReadable(p)) throw new IllegalArgumentException(\"Key file not readable: \" + p);","typeGuard":null,"tryCatchPattern":"try {\n  String key = KeyPairUtils.readPrivateKeyFile(path);\n} catch (RuntimeException e) {\n  throw new IllegalArgumentException(\"Failed to load private key at \" + path + \": \" + e.getMessage(), e);\n}","preventionTips":["Resolve '~' manually — Java does not expand it.","Stage the key file with the job or bake it into the container image.","Use absolute paths everywhere."],"tags":["java","file-io","snowflake","private-key"],"backgroundTag":"file-not-found","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}