Skip to content

Commit

Permalink
Improves error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
cipharius committed Nov 8, 2021
1 parent 28ee689 commit 1ff9bf0
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/msgpack.lua
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ local function parse(message: string, offset: number): (any, number)

end

error("Not all decoder cases are handled")
error("Not all decoder cases are handled, report as bug to msgpack-luau maintainer")
end

local function encode(data: any, tableSet: {[any]: boolean}): string
Expand Down Expand Up @@ -426,7 +426,7 @@ local function encode(data: any, tableSet: {[any]: boolean}): string
) .. data
end

error("Too long string")
error("Could not encode - too long string")

elseif type(data) == "number" then
-- represents NaN, Inf, -Inf as float 32 to save space
Expand Down Expand Up @@ -570,7 +570,7 @@ local function encode(data: any, tableSet: {[any]: boolean}): string
) .. extensionData
end

error("Too long extension data")
error("Could not encode - too long extension data")
elseif msgpackType == msgpack.ByteArray then
data = data.data
local length = #data
Expand All @@ -593,7 +593,7 @@ local function encode(data: any, tableSet: {[any]: boolean}): string
) .. data
end

error("Too long BinaryArray")
error("Could not encode - too long BinaryArray")
end
end

Expand Down Expand Up @@ -629,7 +629,7 @@ local function encode(data: any, tableSet: {[any]: boolean}): string
extract(length, 0, 8)
)
else
error("Too long array")
error("Could not encode - too long array")
end

local encodedValues = table.create(length + 1)
Expand Down Expand Up @@ -660,7 +660,7 @@ local function encode(data: any, tableSet: {[any]: boolean}): string
extract(mapLength, 0, 8)
)
else
error("Too long map")
error("Could not encode - too long map")
end

local encodedPairs = tableCreate(2*mapLength + 1)
Expand All @@ -677,7 +677,7 @@ local function encode(data: any, tableSet: {[any]: boolean}): string
end
end

error("Not all encoder cases are handled")
error(string.format("Could not encode - unsupported datatype \"%s\"", typeof(data)))
end

msgpack.Int64 = {}
Expand Down Expand Up @@ -721,7 +721,7 @@ end

function msgpack.decode(message: string): any
if message == "" then
error("Message is too short")
error("Could not decode - input string is too short")
end
return (parse(message, 0))
end
Expand Down

0 comments on commit 1ff9bf0

Please sign in to comment.