facebook / akd

An implementation of an auditable key directory

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Convert Invalid Directional Movements During Preloading to Compile-time Errors

dillonrg opened this issue · comments

In #312, we discovered that during preloading in the Azks struct there exists a codepath which "moves" in valid directions (e.g., left and right) as specified by the DIRECTIONS constant within akd_core. As part of these valid moves, we invoke the get_child_label method defined within tree_node, which never throws in the event valid directions are passed to it as arguments.

Considering that we are only ever moving in "valid" directions as defined by the constant, we panic if we attempt to move in an "invalid" direction according to the get_child_label method. The rationale is that panicking is valid in this case, as we really should never attempt to move in an invalid direction and that may indicate a bug within akd. Panicking here is done in an attempt to better surface "shouldn't happen" scenarios.

Overall, we'd prefer any attempts to move in an invalid direction to be a compile-time error. That is, instead of panicking at runtime and crashing the server, we'd like to prevent akd from compiling altogether. Potential solutions include encoding only valid directions as their own type, but further evaluation is required before a concrete solution is reached.