-
Notifications
You must be signed in to change notification settings - Fork 95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make it possible for combine::primitives::ParseError
to be std::error::Error
for more range types
#86
Comments
Oh, I forgot a wrinkle: we want Maybe what I want is to require |
This I think is the first problem we should solve. For the errors actually created by the parser I don't see any way around the the errors having lifetimes in them. I think the best way to work around that is to make it easy to transform a
I always wanted to this change but I have held out waiting for rust-lang/rust#21903. If that issue were fixed it should be possible to do type ParseError<S: StreamOnce> = ParseErrorEx<S::Position, S::Item, S::Range>;
struct ParseErrorEx<P, I, R> { .. } |
Ah, interesting, that would be nice. I didn't want to generalize Locally, I have elected to post-process |
It's possible to `map_err_range` for `ParseResult<>` too, but it's awkward because the output type needs to be a compatible `StreamOnce`. As suggested in Marwes#86 (comment), it's probably best to either change the parse result type entirely, or wait for rust-lang/rust#21903. This at least helps consumers convert `ParseError<>` into something that can implement `std::fmt::Display`.
It's possible to `map_err_range` for `ParseResult<>` too, but it's awkward because the output type needs to be a compatible `StreamOnce`. As suggested in Marwes#86 (comment), it's probably best to either change the parse result type entirely, or wait for rust-lang/rust#21903. This at least helps consumers convert `ParseError<>` into something that can implement `std::fmt::Display`.
Add map functions for Error<> and Info<> ranges. (#86)
This can be simplified when Marwes/combine#86 makes it to a published release, but this unblocks us for now. This converts the `combine` error type `ParseError<&'a [edn::Value]>` to a type with owned `Vec<edn::Value>` collections, re-using `edn::Value::Vector` for making them `Display`.
This can be simplified when Marwes/combine#86 makes it to a published release, but this unblocks us for now. This converts the `combine` error type `ParseError<&'a [edn::Value]>` to a type with owned `Vec<edn::Value>` collections, re-using `edn::Value::Vector` for making them `Display`.
…#348. (#341) * Pre: Drop unneeded tx0 from search results. * Pre: Don't require a schema in some of the DB code. The idea is to separate the transaction applying code, which is schema-aware, from the concrete storage code, which is just concerned with getting bits onto disk. * Pre: Only reference Schema, not DB, in debug module. This is part of a larger separation of the volatile PartitionMap, which is modified every transaction, from the stable Schema, which is infrequently modified. * Pre: Fix indentation. * Extract part of DB to new SchemaTypeChecking trait. * Extract part of DB to new PartitionMapping trait. * Pre: Don't expect :db.part/tx partition to advance when tx fails. This fails right now, because we allocate tx IDs even when we shouldn't. * Sketch a db interface without DB. * Add ValueParseError; use error-chain in tx-parser. This can be simplified when Marwes/combine#86 makes it to a published release, but this unblocks us for now. This converts the `combine` error type `ParseError<&'a [edn::Value]>` to a type with owned `Vec<edn::Value>` collections, re-using `edn::Value::Vector` for making them `Display`. * Pre: Accept Borrow<Schema> instead of just &Schema in debug module. This makes it easy to use Rc<Schema> or Arc<Schema> without inserting &* sigils throughout the code. * Use error-chain in query-parser. There are a few things to point out here: - the fine grained error types have been flattened into one crate-wide error type; it's pretty easy to regain the granularity as needed. - edn::ParseError is automatically lifted to mentat_query_parser::errors::Error; - we use mentat_parser_utils::ValueParser to maintain parsing error information from `combine`. * Patch up top-level. * Review comment: Only `borrow()` once.
…#328. r=rnewman (#341) * Pre: Drop unneeded tx0 from search results. * Pre: Don't require a schema in some of the DB code. The idea is to separate the transaction applying code, which is schema-aware, from the concrete storage code, which is just concerned with getting bits onto disk. * Pre: Only reference Schema, not DB, in debug module. This is part of a larger separation of the volatile PartitionMap, which is modified every transaction, from the stable Schema, which is infrequently modified. * Pre: Fix indentation. * Extract part of DB to new SchemaTypeChecking trait. * Extract part of DB to new PartitionMapping trait. * Pre: Don't expect :db.part/tx partition to advance when tx fails. This fails right now, because we allocate tx IDs even when we shouldn't. * Sketch a db interface without DB. * Add ValueParseError; use error-chain in tx-parser. This can be simplified when Marwes/combine#86 makes it to a published release, but this unblocks us for now. This converts the `combine` error type `ParseError<&'a [edn::Value]>` to a type with owned `Vec<edn::Value>` collections, re-using `edn::Value::Vector` for making them `Display`. * Pre: Accept Borrow<Schema> instead of just &Schema in debug module. This makes it easy to use Rc<Schema> or Arc<Schema> without inserting &* sigils throughout the code. * Use error-chain in query-parser. There are a few things to point out here: - the fine grained error types have been flattened into one crate-wide error type; it's pretty easy to regain the granularity as needed. - edn::ParseError is automatically lifted to mentat_query_parser::errors::Error; - we use mentat_parser_utils::ValueParser to maintain parsing error information from `combine`. * Patch up top-level. * Review comment: Only `borrow()` once.
This will make mappings over parse errors be possible as desired in #86 BREAKING CHANGE Changes the type parameters of `ParseError`
This will make mappings over parse errors be possible as desired in #86 BREAKING CHANGE Changes the type parameters of `ParseError`
This will make mappings over parse errors be possible as desired in #86 BREAKING CHANGE Changes the type parameters of `ParseError`
Over in https://github.com/mozilla/mentat, we're using
combine
to parse&'a [edn::Value]
slices. Here,edn::Value
is a generic value type conceptually similar to JSON. What is happening here is not specific toedn::Value
, so I'll useT
: we're usingcombine
to parse&'a [T]
streams.The error type of such a
Parser
iscombine::primitives::ParseError<&'a [T]>
. Now, aroundcombine/src/primitives.rs
Line 449 in 6f2cec6
std::error::Error
only when the underlyingStream::Range
isstd::fmt::Display
. However, no slice&'a [T]
can ever satisfy this trait bound due to rust-lang/rust#39328.I can think of the following ways to work around this issue:
std::error::Error
for&'a [edn::Value]
.Even with specialization, this may not allow to solve the problem, depending on the restrictions on third-party types.
&'a [T]
streams in a newtype implementingStream
, and wrap theStream::Range
type as well.I have done this locally; it's not hard, but I expect it to have a non-trivial runtime cost, since all ranges need to be wrapped and unwrapped. I'd be surprised if the compiler could make this zero-cost, but I'd love to be amazed.
Range
trait specifically for wrapping or otherwise helping formatRange
instances.I doubt this would be difficult, but it would be a breaking API change: existing consumers with non-default
Range
implementations would have to add the new method, even if they didn't care about this issue (which they can't have been using without significant effort).RangeDisplay
trait incombine
, define it for theRange
types incombine
, and expect that in thestd::error::Error
implementation.This is the least intrusive solution, but ties all
Range
implementations to a single display format. I think this is okay, though -- it's already the case that&str
ranges have a single display format.@Marwes, have you thought about this problem? Is there an alternate approach you can suggest? Would you accept a patch for one of the final two proposed solutions?
The text was updated successfully, but these errors were encountered: