Skip to content
This repository has been archived by the owner on Nov 6, 2022. It is now read-only.

Facility to report detailed parsing errors. #43

Merged
merged 1 commit into from
Jun 19, 2011
Merged

Facility to report detailed parsing errors. #43

merged 1 commit into from
Jun 19, 2011

Conversation

pgriess
Copy link
Contributor

@pgriess pgriess commented May 24, 2011

  • Add http_errno enum w/ values for many parsing error conditions.
  • Add http_parser_result struct which tracks errno value and line number
    where error occurred; add http_parser_execute_result() which takes
    this as an outparam. Use extra struct vs. augmenting http_parser to
    keep per-conn state small.
  • Add http_errno_*() methods to help turning errno values into
    human-readable messages.

@pgriess
Copy link
Contributor Author

pgriess commented May 24, 2011

I'm not in love with the API changes, but I think the functionality is right.

I'd have preferred to dump the result data into http_parser but didn't want to inflate the struct since I know you worked hard to make it so small. That said, it's just 8 extra bytes ;)

Also, I opted against creating RETURN_SET_ERRNO() and GOTO_SET_ERRNO() macros as I wanted to keep flow-control logic visible in the main function body.

@mnot
Copy link

mnot commented May 24, 2011

+1 from an HTTP angle.

@pgriess
Copy link
Contributor Author

pgriess commented Jun 3, 2011

Any thoughts on this? Happy to iterate on it.

@clifffrey
Copy link
Contributor

I don't really like adding the extra argument to http_parser_execute. My gut feeling says to do one of three things instead:

  1. Just add a uint8_t field to the http_parser struct that contains the errno. I would drop the line number I think.
  2. Use the "state" field. Just have the error numbers go from 128 and up or something. You could add a function http_parser_get_errno that would return 0 if state is < 128, and return state - 128 otherwise.

The downside of (2) is that it makes the error non-recoverable, but I am having trouble imagining a use-case for recoverable errors.

I think that this is awesome data to add, that will be very useful for logging of errors. I don't really like the line number because that is not what we want to maintain/reveal.

@mnot
Copy link

mnot commented Jun 3, 2011

There are a couple of recoverable HTTP parsing errors; e.g., the header line without a colon (that's not a continuation), as discussed recently on-list.

I agree, however, that they're pretty rare, and in the 99% case you can determine a single behaviour that's good for everyone. The exception is if someone wants to build a validator or HTTP traffic inspector using the parser; in that case you really need that deep information, and you need to be able to recover (so that one error doesn't stop inspection).

However, this is a very specialised use case (obviously) that it'd be easy to say is just out of scope.

@ry
Copy link
Contributor

ry commented Jun 4, 2011

I like @clifffrey's (2) suggestion

@pgriess
Copy link
Contributor Author

pgriess commented Jun 4, 2011

Ok, I'll go with (2). I hate the API mangling that went into the existing change anyway ;)

I do, however, feel somewhat strongly about exposing source-level information. This is quite useful for debugging (e.g. to figure out which of the 12 callsites that set INVALID_VERSION w/o setting a breakpoint on all of them). I'll update the pull with a a uint16_t line number that's visible only under (the to be created) HTTP_PARSER_DEBUG flag and see what you guys think.

@clifffrey
Copy link
Contributor

The change looks good to me.
It would be cool to change test_simple to specifically take the error code that we expect to be returned, but the change is worth checking in even without that.

- Add http_errno enum w/ values for many parsing error conditions. Stash
  this in http_parser.state if the 0x80 bit is set.
- Report line numbers on error generation if the (new) HTTP_PARSER_DEBUG
  cpp symbol is set. Increases http_parser struct size by 8 bytes in
  this case.
- Add http_errno_*() methods to help turning errno values into
  human-readable messages.
pgriess added a commit that referenced this pull request Jun 19, 2011
Facility to report detailed parsing errors.
@pgriess pgriess merged commit 0aa3e52 into nodejs:master Jun 19, 2011
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants