Open warpfork opened 4 years ago
To try to answer some of the questions posed by this, my current thinking is:
ErrNotFound
type sounds like a reasonable way forward. (This would probably do better for "cost-effective explanatory" as mentioned in previous point.)ErrNotFound
type have an optional spot for Path
info, so that we don't need a separate type for traversal
to use?
ErrNotFound
, why not keep rolling?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.
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 theLookupBy{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:
schema.ErrNoSuchField
type for this, but it's possible that was a mistake and should be removed.ipld.ErrInvalidKey
type used for this. Inconsistently, vs the above, apparently :(ipld.ErrInvalidKey
type which is used here.schema.ErrInvalidUnionDiscriminant
type for this, but it's possible that wouldn't help as much as it confuses.schema.ErrEnumNotMatched
? (Such an error type is also not yet present.)optional
can be in this state.LookupBySegment
on a map when thePathSegment
is an int, or in the other direction, when a string segment is used on a list node.LookupByNode
? Should it attempt to coerce things? Or return "not found" errors? Or return a different type of error which points out the need to convert things manually?LookupBySegment
, too: except "wrong kind" definitely wouldn't suffice here, since things can be right kind but wrong type withLookupByNode
.traversal
package: which are caused by one of the above, but also should report the path where the error was encounteredtraversal.Progress
like LastLink... 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.