-
Notifications
You must be signed in to change notification settings - Fork 86
Expand file tree
/
Copy patherrors.js
More file actions
executable file
·122 lines (109 loc) · 3.11 KB
/
errors.js
File metadata and controls
executable file
·122 lines (109 loc) · 3.11 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/**
* @fileoverview Standard error messages for errors detected when parsing
* binary protos.
*/
goog.module('jspb.binary.errors');
// N.B. In the functions below invoke the `Error` constructor directly in order
// to be compatible with the string replacement semantics in the JsCompiler,
// which typically matches on strings passed to the Error constructor.
/**
* Reports that we didn't read the number of expected bytes for a message.
* @return {!Error}
*/
function messageLengthMismatchError(
/** number */ messageLength, /** number */ readLength) {
// NOTE: we directly throw here instead of report because this is what we used
// to do as well.
return new Error(
`Message parsing ended unexpectedly. Expected to read ` +
`${messageLength} bytes, instead read ${readLength} bytes, either the ` +
`data ended unexpectedly or the message misreported its own length`);
}
/**
* Reports an invalid wire type value.
*
* @return {!Error}
*/
function invalidWireTypeError(/** number */ wireType, /** number */ position) {
return new Error(`Invalid wire type: ${wireType} (at position ${position})`);
}
/**
* Reports an invalid field number.
*
* @return {!Error}
*/
function invalidFieldNumberError(
/** number */ fieldNumber, /** number */ position) {
return new Error(
`Invalid field number: ${fieldNumber} (at position ${position})`);
}
/**
* Reports message-set parsing faield
* @return {!Error}
*/
function malformedBinaryBytesForMessageSet() {
return new Error('Malformed binary bytes for message set');
}
/**
* Reports a failure to find an END_GROUP tag because we hit end of stream.
*
* @return {!Error}
*/
function unmatchedStartGroupEofError() {
return new Error('Unmatched start-group tag: stream EOF');
}
/**
* Reports a general failure to find an END_GROUP tag matching a START_GROUP.
*
* @return {!Error}
*/
function unmatchedStartGroupError() {
return new Error('Unmatched end-group tag');
}
/**
* Reports that parsing a group did not end on an END_GROUP tag.
*
* @return {!Error}
*/
function groupDidNotEndWithEndGroupError() {
return new Error('Group submessage did not end with an END_GROUP tag');
}
/**
* Reports that the varint is invalid in some way.
*
* @return {!Error}
*/
function invalidVarintError() {
return new Error('Failed to read varint, encoding is invalid.');
}
/**
* Reports that we read more bytes than were available.
*
* @return {!Error}
*/
function readTooFarError(
/** number */ expectedLength, /** number */ readLength) {
return new Error(`Tried to read past the end of the data ${readLength} > ${
expectedLength}`);
}
/**
* Reports that we read more bytes than were available.
*
* @return {!Error}
*/
function negativeByteLengthError(
/** number */ length) {
return new Error(`Tried to read a negative byte length: ${length}`);
}
exports = {
messageLengthMismatchError,
groupDidNotEndWithEndGroupError,
invalidFieldNumberError,
invalidVarintError,
invalidWireTypeError,
malformedBinaryBytesForMessageSet,
negativeByteLengthError,
readTooFarError,
unmatchedStartGroupError,
unmatchedStartGroupEofError,
};