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

Inconsistent method return when IP address is invalid #69

Open
amh4r opened this issue Mar 24, 2018 · 0 comments
Open

Inconsistent method return when IP address is invalid #69

amh4r opened this issue Mar 24, 2018 · 0 comments

Comments

@amh4r
Copy link

amh4r commented Mar 24, 2018

When the IP address is invalid, some methods throw errors while others return something. There are also a couple methods (e.g. href()) which don't return falsy values. Should this be more consistent? I like how like all boolean methods (e.g. isValid()) return false when the IP address is invalid, but it seems like the others should all throw errors or return null.

The following code calls each method on Address6 when the IP address is invalid.

const Address6 = require('ip-address').Address6
const address = new Address6('intentionally invalid')

for (let key of Object.keys(address.__proto__).sort((a, b) => a < b ? -1 : 1)) {
    if (typeof address[key] === 'function') {
        try {
            console.log(`   OK:  ${key}() = ${address[key]()}`)
        } catch (error) {
            console.log(`ERROR:  ${key}()`)
        }
    }
}

This is the output:

   OK:  bigInteger() = null
ERROR:  binaryZeroPad()
   OK:  canonicalForm() = null
   OK:  correctForm() = null
   OK:  decimal() = null
ERROR:  endAddress()
ERROR:  getBits()
   OK:  getBitsBase16() = null
ERROR:  getBitsBase2()
ERROR:  getBitsPastSubnet()
ERROR:  getScope()
   OK:  getType() = Global unicast
ERROR:  group()
   OK:  href() = http://[null]/
ERROR:  inspect6to4()
ERROR:  inspectTeredo()
   OK:  is4() = false
   OK:  is6to4() = false
   OK:  isCanonical() = false
   OK:  isCorrect() = false
   OK:  isInSubnet() = false
   OK:  isLinkLocal() = false
   OK:  isLoopback() = false
   OK:  isMulticast() = false
   OK:  isTeredo() = false
   OK:  isValid() = false
   OK:  link() = <a href="/#address=null">null</a>
ERROR:  mask()
ERROR:  microsoftTranscription()
ERROR:  parse()
ERROR:  parse4in6()
   OK:  possibleSubnets() = 1
ERROR:  regularExpression()
ERROR:  regularExpressionString()
ERROR:  reverseForm()
ERROR:  startAddress()
ERROR:  to4()
ERROR:  to4in6()
   OK:  to6to4() = null
ERROR:  toByteArray()
ERROR:  toUnsignedByteArray()
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

1 participant