Skip to content

readConfigVarFromFilesystem returning None on error hides the root cause #967

@ptrdom

Description

@ptrdom

Versions used

Akka version: 2.6.13

Description

Currently KubernetesApiServiceDiscovery.readConfigVarFromFilesystem method returns None in case of an error reading from a file. This causes complications down the line when trying to identify what is going on. For example, I had an issue where reading the file threw permissions errors. Discovery process proceeds and simply fails to make k8s API requests because it no longer provides Bearer tokens. Error is still logged, but it gets quickly obscured by all the error logs about permissions for anonymous user account, so the root cause gets effectively hidden, making this a gotcha that each developer has to learn. I think this kind of exception should be treated more severely, maybe even by terminating the application, because this is basically a fatal error. Would implementing that make sense?

private def readConfigVarFromFilesystem(path: String, name: String): Option[String] = {
val file = Paths.get(path)
if (Files.exists(file)) {
try {
Some(new String(Files.readAllBytes(file), "utf-8"))
} catch {
case NonFatal(e) =>
log.error(e, "Error reading {} from {}", name, path)
None
}
} else {
log.warning("Unable to read {} from {} because it doesn't exist.", name, path)
None
}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions