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

@ -10,7 +10,7 @@ proc callC() = callA()
try:
callC()
except AssertionError:
except AssertionDefect:
write(stdout, "assertion failure!")
except:
write(stdout, "unknown exception!")

View file

@ -18,12 +18,12 @@ type
try:
doAssert(false, "msg1") # doAssert test
except AssertionError as e:
except AssertionDefect as e:
assert e.msg.endsWith "tassert2.nim(20, 11) `false` msg1"
try:
assert false # assert test with no msg
except AssertionError as e:
except AssertionDefect as e:
assert e.msg.endsWith "tassert2.nim(25, 10) `false` "
try:
@ -31,13 +31,13 @@ try:
doAssert(a+a==1) # assert test with Ast expression
# BUG: const folding would make "1+1==1" appear as `false` in
# assert message
except AssertionError as e:
except AssertionDefect as e:
assert e.msg.endsWith "`a + a == 1` "
try:
let a = 1
doAssert a+a==1 # ditto with `doAssert` and no parens
except AssertionError as e:
except AssertionDefect as e:
assert e.msg.endsWith "`a + a == 1` "
proc fooStatic() =
@ -91,14 +91,14 @@ block: ## checks for issue https://github.com/nim-lang/Nim/issues/8518
try:
doAssert fun("foo1") == fun("foo2"), "mymsg"
except AssertionError as e:
except AssertionDefect as e:
# used to expand out the template instantiaiton, sometimes filling hundreds of lines
assert e.msg.endsWith ""
block: ## checks for issue https://github.com/nim-lang/Nim/issues/9301
try:
doAssert 1 + 1 == 3
except AssertionError as e:
except AssertionDefect as e:
# used to const fold as false
assert e.msg.endsWith "tassert2.nim(100, 14) `1 + 1 == 3` "
@ -106,6 +106,6 @@ block: ## checks AST isn't transformed as it used to
let a = 1
try:
doAssert a > 1
except AssertionError as e:
except AssertionDefect as e:
# used to rewrite as `1 < a`
assert e.msg.endsWith "tassert2.nim(108, 14) `a > 1` "

View file

@ -33,7 +33,7 @@ try:
proc foo() =
assert(false)
foo()
except AssertionError:
except AssertionDefect:
let e = getCurrentException()
let trace = e.getStackTrace
if tmatch(trace, expected): echo true else: echo "wrong trace:\n" & trace