forked from uber/bufrw
-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors.js
130 lines (114 loc) · 3.96 KB
/
errors.js
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
123
124
125
126
127
128
129
130
// Copyright (c) 2015 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
'use strict';
var TypedError = require('error/typed');
var WrappedError = require('error/wrapped');
module.exports.expected = function expected(got, descr) {
return module.exports.InvalidArgument({
expected: descr,
argType: typeof got,
argConstructor: got && got.constructor.name
});
};
module.exports.BrokenReaderState = TypedError({
type: 'bufrw.broken-reader-state',
message: 'reader in invalid state {state} expecting {expecting} avail {aval}',
state: null,
expecting: null,
avail: null
});
module.exports.FixedLengthMismatch = TypedError({
type: 'bufrw.fixed-length-mismatch',
message: 'supplied length {got} mismatches fixed length {expected}',
expected: null,
got: null
});
module.exports.RangeError = TypedError({
type: 'bufrw.range-error',
message: 'value {value} out of range, min: {min} max: {max}',
value: null,
min: null,
max: null
});
module.exports.InvalidArgument = TypedError({
type: 'bufrw.invalid-argument',
message: 'invalid argument, expected {expected}',
expected: null,
argType: null,
argConstructor: null
});
module.exports.InvalidSwitchValue = TypedError({
type: 'bufrw.invalid-switch-value',
message: 'invalid switch value {value}',
value: null
});
module.exports.MissingStructField = TypedError({
type: 'bufrw.missing.struct-field',
message: 'missing field {field} on {struct}',
field: null,
struct: null
});
module.exports.ShortBuffer = TypedError({
type: 'bufrw.short-buffer',
message: 'expected at least {expected} bytes, only have {actual} @{offset}',
expected: null,
actual: null,
buffer: null,
offset: null
});
module.exports.ShortBufferRanged = TypedError({
type: 'bufrw.short-buffer',
message: 'expected at least {expected} bytes, only have {actual} @[{offset}:{endOffset}]',
expected: null,
actual: null,
offset: null,
endOffset: null
});
module.exports.ShortRead = TypedError({
type: 'bufrw.short-read',
message: 'short read, {remaining} byte left over after consuming {offset}',
remaining: null,
buffer: null,
offset: null
});
module.exports.ShortWrite = TypedError({
type: 'bufrw.short-write',
message: 'short write, {remaining} byte left over after writing {offset}',
remaining: null,
buffer: null,
offset: null
});
module.exports.TruncatedRead = TypedError({
type: 'bufrw.truncated-read',
message: 'read truncated by end of stream with {length} bytes in buffer',
length: null,
buffer: null,
state: null,
expecting: null
});
module.exports.UnstableRW = WrappedError({
type: 'bufrw.unstable-rw',
message: 'Unstable RW error: {origMessage} (other: {otherMessage})',
otherMessage: null
});
module.exports.ZeroLengthChunk = TypedError({
type: 'bufrw.zero-length-chunk',
message: 'zero length chunk encountered'
});