-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors.go
More file actions
48 lines (43 loc) · 1.86 KB
/
Copy patherrors.go
File metadata and controls
48 lines (43 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package httpparser
import (
"errors"
"fmt"
)
// Error kinds returned (wrapped in a *ParseError) by the Parse functions.
// Callers can test for them with errors.Is.
var (
// ErrMalformedRequestLine indicates a request line that does not contain
// at least a method and a URL.
ErrMalformedRequestLine = errors.New("malformed request line")
// ErrUnsupportedMethod indicates a request line whose method is not one of
// the supported HTTP methods.
ErrUnsupportedMethod = errors.New("unsupported method")
// ErrMalformedHeader indicates a header line that is not a "Key: Value"
// pair with a non-empty key.
ErrMalformedHeader = errors.New("malformed header")
// ErrMalformedAssertion indicates a "# @expect" directive that cannot be
// parsed.
ErrMalformedAssertion = errors.New("malformed assertion")
// ErrMalformedScript indicates a "< ..." pre-request or "> ..." response
// handler directive that cannot be parsed, such as an inline "{%" block with
// no closing "%}" or an external reference with no path.
ErrMalformedScript = errors.New("malformed script")
)
// ParseError describes a syntax error at a specific line of a .http file. It
// wraps one of the Err* sentinels, so errors.Is(err, ErrUnsupportedMethod) and
// friends report the kind of failure, while the Line and Detail fields give the
// location and the offending text.
type ParseError struct {
// Line is the 1-indexed file line number where the error was found.
Line int
// Kind is one of the exported Err* sentinels.
Kind error
// Detail is the offending text (the request line, header line, etc.).
Detail string
}
// Error implements the error interface.
func (e *ParseError) Error() string {
return fmt.Sprintf("httpparser: %s at line %d: %q", e.Kind, e.Line, e.Detail)
}
// Unwrap returns the underlying Err* sentinel so errors.Is can match on it.
func (e *ParseError) Unwrap() error { return e.Kind }