mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
Stopped throwing literals :/
This commit is contained in:
@@ -6,7 +6,7 @@ export default class Decoder {
|
||||
|
||||
checkEOS(length: number) {
|
||||
if (this.index + length > this.buffer.length) {
|
||||
throw 'end of stream'
|
||||
throw new Error('end of stream')
|
||||
}
|
||||
}
|
||||
next() {
|
||||
@@ -48,7 +48,7 @@ export default class Decoder {
|
||||
if (value >= 0 && value < 16) {
|
||||
return value < 10 ? '0'.charCodeAt(0) + value : 'A'.charCodeAt(0) + value - 10
|
||||
}
|
||||
throw 'invalid hex: ' + value
|
||||
throw new Error('invalid hex: ' + value)
|
||||
}
|
||||
unpackNibble(value: number) {
|
||||
if (value >= 0 && value <= 9) {
|
||||
@@ -62,7 +62,7 @@ export default class Decoder {
|
||||
case 15:
|
||||
return '\0'.charCodeAt(0)
|
||||
default:
|
||||
throw 'invalid nibble: ' + value
|
||||
throw new Error('invalid nibble: ' + value)
|
||||
}
|
||||
}
|
||||
unpackByte(tag: number, value: number) {
|
||||
@@ -71,7 +71,7 @@ export default class Decoder {
|
||||
} else if (tag === WA.Tags.HEX_8) {
|
||||
return this.unpackHex(value)
|
||||
} else {
|
||||
throw 'unknown tag: ' + tag
|
||||
throw new Error('unknown tag: ' + tag)
|
||||
}
|
||||
}
|
||||
readPacked8(tag: number) {
|
||||
@@ -90,7 +90,7 @@ export default class Decoder {
|
||||
}
|
||||
readRangedVarInt(min, max, description = 'unknown') {
|
||||
// value =
|
||||
throw 'WTF; should not be called'
|
||||
throw new Error('WTF; should not be called')
|
||||
}
|
||||
isListTag(tag: number) {
|
||||
return tag === WA.Tags.LIST_EMPTY || tag === WA.Tags.LIST_8 || tag === WA.Tags.LIST_16
|
||||
@@ -104,7 +104,7 @@ export default class Decoder {
|
||||
case WA.Tags.LIST_16:
|
||||
return this.readInt(2)
|
||||
default:
|
||||
throw 'invalid tag for list size: ' + tag
|
||||
throw new Error('invalid tag for list size: ' + tag)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,12 +134,12 @@ export default class Decoder {
|
||||
if (i && j) {
|
||||
return i + '@' + j
|
||||
}
|
||||
throw 'invalid jid pair: ' + i + ', ' + j
|
||||
throw new Error('invalid jid pair: ' + i + ', ' + j)
|
||||
case WA.Tags.HEX_8:
|
||||
case WA.Tags.NIBBLE_8:
|
||||
return this.readPacked8(tag)
|
||||
default:
|
||||
throw 'invalid string with tag: ' + tag
|
||||
throw new Error('invalid string with tag: ' + tag)
|
||||
}
|
||||
}
|
||||
readAttributes(n: number) {
|
||||
@@ -161,14 +161,14 @@ export default class Decoder {
|
||||
}
|
||||
getToken(index: number) {
|
||||
if (index < 3 || index >= WA.SingleByteTokens.length) {
|
||||
throw 'invalid token index: ' + index
|
||||
throw new Error('invalid token index: ' + index)
|
||||
}
|
||||
return WA.SingleByteTokens[index]
|
||||
}
|
||||
getTokenDouble(index1, index2): string {
|
||||
const n = 256 * index1 + index2
|
||||
if (n < 0 || n > WA.DoubleByteTokens.length) {
|
||||
throw 'invalid double token index: ' + n
|
||||
throw new Error('invalid double token index: ' + n)
|
||||
}
|
||||
return WA.DoubleByteTokens[n]
|
||||
}
|
||||
@@ -176,12 +176,12 @@ export default class Decoder {
|
||||
const listSize = this.readListSize(this.readByte())
|
||||
const descrTag = this.readByte()
|
||||
if (descrTag === WA.Tags.STREAM_END) {
|
||||
throw 'unexpected stream end'
|
||||
throw new Error('unexpected stream end')
|
||||
}
|
||||
|
||||
const descr = this.readString(descrTag)
|
||||
if (listSize === 0 || !descr) {
|
||||
throw 'invalid node'
|
||||
throw new Error('invalid node')
|
||||
}
|
||||
|
||||
const attrs = this.readAttributes((listSize - 1) >> 1)
|
||||
|
||||
@@ -25,7 +25,7 @@ export default class Encoder {
|
||||
}
|
||||
writeByteLength(length: number) {
|
||||
if (length >= 4294967296) {
|
||||
throw 'string too large to encode: ' + length
|
||||
throw new Error('string too large to encode: ' + length)
|
||||
}
|
||||
if (length >= 1 << 20) {
|
||||
this.pushByte(WA.Tags.BINARY_32)
|
||||
@@ -51,7 +51,7 @@ export default class Encoder {
|
||||
if (token < 245) {
|
||||
this.pushByte(token)
|
||||
} else if (token <= 500) {
|
||||
throw 'invalid token'
|
||||
throw new Error('invalid token')
|
||||
}
|
||||
}
|
||||
writeString(token: string, i: boolean = null) {
|
||||
@@ -69,7 +69,7 @@ export default class Encoder {
|
||||
const overflow = tokenIndex - WA.Tags.SINGLE_BYTE_MAX
|
||||
const dictionaryIndex = overflow >> 8
|
||||
if (dictionaryIndex < 0 || dictionaryIndex > 3) {
|
||||
throw 'double byte dict token out of range: ' + token + ', ' + tokenIndex
|
||||
throw new Error('double byte dict token out of range: ' + token + ', ' + tokenIndex)
|
||||
}
|
||||
this.writeToken(WA.Tags.DICTIONARY_0 + dictionaryIndex)
|
||||
this.writeToken(overflow % 256)
|
||||
@@ -118,7 +118,7 @@ export default class Encoder {
|
||||
this.writeByteLength(buffer.length)
|
||||
this.pushBytes(buffer)
|
||||
} else {
|
||||
throw 'invalid children: ' + children + ' (' + typeof children + ')'
|
||||
throw new Error('invalid children: ' + children + ' (' + typeof children + ')')
|
||||
}
|
||||
}
|
||||
getValidKeys(obj: Object) {
|
||||
@@ -128,7 +128,7 @@ export default class Encoder {
|
||||
if (!node) {
|
||||
return
|
||||
} else if (node.length !== 3) {
|
||||
throw 'invalid node given: ' + node
|
||||
throw new Error('invalid node given: ' + node)
|
||||
}
|
||||
const validAttributes = this.getValidKeys(node[1])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user