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
Port TransferCoding/Transfer-Encoding to cats-parse #4023
Conversation
ecd40f7
to
256b7c6
Compare
256b7c6
to
02df3dc
Compare
I think you took non-converted files, so I believe nobody has covered them yet. Please notify in the thread #3984 that few more parsers are covered. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice. I particularly like having fromParser
helper. That was overdue, and we should retrofit the others onto it. Small tweaks below.
@@ -77,6 +78,10 @@ object ParseResult { | |||
case NonFatal(e) => Left(ParseFailure(sanitized, e.getMessage)) | |||
} | |||
|
|||
private[http4s] def fromParser[A](parser: Parser[A], errorMessage: => String)( | |||
s: String): ParseResult[A] = | |||
parser.parseAll(s).leftMap(e => ParseFailure(errorMessage, e.toString)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's nice to centralize this, because we're going to need to do better than that e.toString
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, this was what I saw in the other places this pattern was used. Will investigate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, what we get out of Parser.Error
is an offset where the parsing failed, and a list of expected inputs that it didn't find. I can format that in a decently nice way, but it's not going be as good as the ErrorFormatter from parboiled.
An alternative is to do something like https://github.com/http4s/http4s/blob/main/core/src/main/scala/org/http4s/HttpVersion.scala#L58 and repeat the input instead of giving parser-specific errors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new LocationMap
in cats-parse helps turn input into a row-column index and is designed to help with formatting. Oscar mentioned some code in bosatsu that formats errors, but I haven't gone hunting for it.
I suspect there's an opportunity to do a decent default rendering in cats-parse on that LocationMap
.
See #3984
I don't have the complete overview of what is being done on which branch, so I hope noone has done this already.
I added a little helper, that I could envision being used in many of these header parsers, I can remove that again if we want to avoid that kind of thing.