ipld / go-ipld-prime

Golang interfaces for the IPLD Data Model, with core Codecs included, IPLD Schemas support, and some handy functional transforms tools.
MIT License
132 stars 50 forks source link

Review of traversal and "not found" errors #74

Open warpfork opened 4 years ago

warpfork commented 4 years ago

There should be a consistent and well-documented approach to errors around "not found" values, both when encountered by the traversal package, and where they arise from single-step moves across nodes (e.g. via the LookupBy{String|Index|Node|etc}() methods).

(Currently, this is not the case: the traversal package has untyped errors formed by string concatenation (yuck), and in individual nodes, I've done what "seems right" on a case-by-case basis, hoping that a single coherent picture would emerge after doing this for a while. (It has not.) Direct effort is now needed to clean this up and coherentify it.)

Part of the process of solving this involves deciding how many discrete "not found" concepts there are, and which of these are worth discrete error types (or if we should make a single error type with an enum field describing which kind of "not found" this one is, as a detail; or etc).

This issue is just going to enumerate scenarios I've discovered as relevant. Not all of them were obvious until I started writing code that encountered them, so this list is useful to gather in one place. (It's a long list -- sorry, reader. This is "exploration report"-style content moreso than problem-solving, so far, so it's inclusive, rather than simplifying.)

In rough order of increasing complexity of scenario:

... and that should be about exhaustive.

We can try to break this down in the comments. In general I suspect this should probably collapse down to as few error types as possible, but haven't determined how exactly that should best be done.

warpfork commented 4 years ago

To try to answer some of the questions posed by this, my current thinking is:

I don't know what to do with LookupByNode and the coercion questions, but also think those might turn out to be an ignorable tangent for figuring out the overall strategy here.