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:
parent
cd9af6b804
commit
7d6cbf290a
92 changed files with 323 additions and 300 deletions
|
|
@ -19,10 +19,10 @@ when not defined(nimHasSinkInference):
|
|||
{.pragma: nosinks.}
|
||||
|
||||
proc raiseAssert*(msg: string) {.noinline, noreturn, nosinks.} =
|
||||
sysFatal(AssertionError, msg)
|
||||
sysFatal(AssertionDefect, msg)
|
||||
|
||||
proc failedAssertImpl*(msg: string) {.raises: [], tags: [].} =
|
||||
# trick the compiler to not list ``AssertionError`` when called
|
||||
# trick the compiler to not list ``AssertionDefect`` when called
|
||||
# by ``assert``.
|
||||
type Hide = proc (msg: string) {.noinline, raises: [], noSideEffect,
|
||||
tags: [].}
|
||||
|
|
@ -40,9 +40,9 @@ template assertImpl(cond: bool, msg: string, expr: string, enabled: static[bool]
|
|||
failedAssertImpl(ploc & " `" & expr & "` " & msg)
|
||||
|
||||
template assert*(cond: untyped, msg = "") =
|
||||
## Raises ``AssertionError`` with `msg` if `cond` is false. Note
|
||||
## that ``AssertionError`` is hidden from the effect system, so it doesn't
|
||||
## produce ``{.raises: [AssertionError].}``. This exception is only supposed
|
||||
## Raises ``AssertionDefect`` with `msg` if `cond` is false. Note
|
||||
## that ``AssertionDefect`` is hidden from the effect system, so it doesn't
|
||||
## produce ``{.raises: [AssertionDefect].}``. This exception is only supposed
|
||||
## to be caught by unit testing frameworks.
|
||||
##
|
||||
## The compiler may not generate any code at all for ``assert`` if it is
|
||||
|
|
@ -80,7 +80,7 @@ template onFailedAssert*(msg, code: untyped): untyped {.dirty.} =
|
|||
code
|
||||
|
||||
template doAssertRaises*(exception: typedesc, code: untyped) =
|
||||
## Raises ``AssertionError`` if specified ``code`` does not raise the
|
||||
## Raises ``AssertionDefect`` if specified ``code`` does not raise the
|
||||
## specified exception. Example:
|
||||
##
|
||||
## .. code-block:: nim
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue