Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't unmarshal -Infinity #46

Open
mngan opened this issue Aug 12, 2021 · 3 comments
Open

Can't unmarshal -Infinity #46

mngan opened this issue Aug 12, 2021 · 3 comments

Comments

@mngan
Copy link

mngan commented Aug 12, 2021

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?

@cheynearista
Copy link
Contributor

@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.

@mngan
Copy link
Author

mngan commented Aug 12, 2021

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.

@cheynearista
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants