goeapi icon indicating copy to clipboard operation
goeapi copied to clipboard

Can't unmarshal -Infinity

Open mngan opened this issue 3 years ago • 3 comments

When trying to unmarshall the output of show interfaces transceiver dom thresholds, you sometimes can come across a channel value with -Infinity. This causes the JSON decoder to fail with an error like this:

interface-diagnostics: invalid character 'I' in numeric literal"

The JSON object in question looks like this:

{
  "interfaces": {
    "Ethernet54/1": {
      "updateTime": 1628733658.605624,
      "displayName": "Ethernet54/1",
      "parameters": {
        "txPower": {
          "channels": {
            "1": -Infinity
          },
          "threshold": {},
          "unit": "dBm"
        },
        "temperature": {
          "channels": {
            "-": 29.703125
          },
          "threshold": {
            "highWarn": 70.0,
            "lowWarn": 0.0,
            "highAlarm": 75.0,
            "lowAlarm": -5.0
          },
          "unit": "C"
        },
        "txBias": {
          "channels": {
            "1": 0.0
          },
          "threshold": {
            "highWarn": 0.0,
            "lowWarn": 0.0,
            "highAlarm": 0.0,
            "lowAlarm": 0.0
          },
          "unit": "mA"
        },
        "rxPower": {
          "channels": {
            "1": -30.0
          },
          "threshold": {},
          "unit": "dBm"
        },
        "voltage": {
          "channels": {
            "-": 3.3201
          },
          "threshold": {
            "highWarn": 3.45,
            "lowWarn": 3.1500000000000004,
            "highAlarm": 3.8000000000000003,
            "lowAlarm": 2.8400000000000003
          },
          "unit": "V"
        }
      },
      "vendorSn": "XXXXXX",
      "mediaType": "40GBASE-SR4"
    }
}

It seems that -Infinity isn't valid JSON, so it isn't supported by the JSON parser. So what is the way to handle this so you can at least skip over this value and still get the rest of the valid data back?

mngan avatar Aug 12 '21 03:08 mngan

@mngan Interesting. What version of EOS are you running against? I would expect EOS to return valid JSON...so I'm inclined to say an issue should be filed against EOS. However, I do agree we should have at least some method to workaround issues like this. Unfortunately, we do not at the moment. Let me look into this more.

cheynearista avatar Aug 12 '21 12:08 cheynearista

I am seeing this on 4.24.2.2F through 4.25.4M. I'll log a case with Arista on this. JSON not defining NaN and Infinity as literals is a little unexpected though.

mngan avatar Aug 12 '21 21:08 mngan

Yeah. It's specifically stated in rfc4627 (https://datatracker.ietf.org/doc/html/rfc4627#section-2.4). There's been debate on this in the past. Even with respect to how python/ruby/etc handle vs Golang. Seems Go is a tad more strict.

cheynearista avatar Aug 13 '21 13:08 cheynearista