Error -> Defect for defects (#13908)

* Error -> Defect for defects

The distinction between Error and Defect is subjective,
context-dependent and somewhat arbitrary, so when looking at an
exception, it's hard to guess what it is - this happens often when
looking at a `raises` list _without_ opening the corresponding
definition and digging through layers of inheritance.

With the help of a little consistency in naming, it's at least possible
to start disentangling the two error types and the standard lib can set
a good example here.
This commit is contained in:
Jacek Sieka 2020-04-28 19:56:01 +02:00 • committed by GitHub
commit 7d6cbf290a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
92 changed files with 323 additions and 300 deletions

View file

@ -1300,18 +1300,18 @@ when isMainModule:
when compileOption("boundChecks"):
try:
let a = testJson["a"][9]
doAssert(false, "IndexError not thrown")
except IndexError:
doAssert(false, "IndexDefect not thrown")
except IndexDefect:
discard
try:
let a = testJson["a"][-1]
doAssert(false, "IndexError not thrown")
except IndexError:
doAssert(false, "IndexDefect not thrown")
except IndexDefect:
discard
try:
doAssert(testJson["a"][0].num == 1, "Index doesn't correspond to its value")
except:
doAssert(false, "IndexError thrown for valid index")
doAssert(false, "IndexDefect thrown for valid index")
doAssert(testJson{"b"}.getStr() == "asd", "Couldn't fetch a singly nested key with {}")
doAssert(isNil(testJson{"nonexistent"}), "Non-existent keys should return nil")
@ -1378,7 +1378,7 @@ when isMainModule:
try:
discard parsed["key2"][12123]
doAssert(false)
except IndexError: doAssert(true)
except IndexDefect: doAssert(true)
var parsed2 = parseFile("tests/testdata/jsontest2.json")
doAssert(parsed2{"repository", "description"}.str ==