Kong / kong

🦍 The Cloud-Native API Gateway and AI Gateway.
https://konghq.com/install/#kong-community
Apache License 2.0
39.22k stars 4.81k forks source link

Error object; bug? #509

Closed Tieske closed 9 years ago

Tieske commented 9 years ago

Consider this code: https://github.com/Mashape/kong/blob/master/kong/tools/utils.lua#L81-L100

Now if I do this;

local p = require("pl.pretty")

local e
e = add_error(e, "key1", "value1")
e = add_error(e, "key2", "value2")
p.dump(e)

e = add_error(e, "key1", "value3")
e = add_error(e, "key1", "value4")
p.dump(e)

e = add_error(e, "key1", "value5")
e = add_error(e, "key1", "value6")
p.dump(e)

I get a table with a lot of nested tables;

{
  key1 = {
    {
      {
        {
          "value1",
          "value3"
        },
        "value4"
      },
      "value5"
    },
    "value6"
  },
  key2 = "value2"
}

And I would have expected errors with the same keys in only one table;

{
  key1 = {
    "value1",
    "value3",
    "value4",
    "value5",
    "value6",
  },
  key2 = "value2"
}

So what is wrong; the code or my expectations?

thibaultcha commented 9 years ago

I have to admit the code of that function is rather weird. I believe the expectations are right, now we'll see if by changing it we break some tests or not

Tieske commented 9 years ago

I'll have a look at it once I get the testsuite to run locally.