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
|
|
@ -12,34 +12,34 @@ include system/indexerrors
|
|||
|
||||
proc raiseRangeError(val: BiggestInt) {.compilerproc, noinline.} =
|
||||
when hostOS == "standalone":
|
||||
sysFatal(RangeError, "value out of range")
|
||||
sysFatal(RangeDefect, "value out of range")
|
||||
else:
|
||||
sysFatal(RangeError, "value out of range: ", $val)
|
||||
sysFatal(RangeDefect, "value out of range: ", $val)
|
||||
|
||||
proc raiseIndexError3(i, a, b: int) {.compilerproc, noinline.} =
|
||||
sysFatal(IndexError, formatErrorIndexBound(i, a, b))
|
||||
sysFatal(IndexDefect, formatErrorIndexBound(i, a, b))
|
||||
|
||||
proc raiseIndexError2(i, n: int) {.compilerproc, noinline.} =
|
||||
sysFatal(IndexError, formatErrorIndexBound(i, n))
|
||||
sysFatal(IndexDefect, formatErrorIndexBound(i, n))
|
||||
|
||||
proc raiseIndexError() {.compilerproc, noinline.} =
|
||||
sysFatal(IndexError, "index out of bounds")
|
||||
sysFatal(IndexDefect, "index out of bounds")
|
||||
|
||||
proc raiseFieldError(f: string) {.compilerproc, noinline.} =
|
||||
sysFatal(FieldError, f)
|
||||
sysFatal(FieldDefect, f)
|
||||
|
||||
proc raiseRangeErrorI(i, a, b: BiggestInt) {.compilerproc, noinline.} =
|
||||
sysFatal(RangeError, "value out of range: " & $i & " notin " & $a & " .. " & $b)
|
||||
sysFatal(RangeDefect, "value out of range: " & $i & " notin " & $a & " .. " & $b)
|
||||
|
||||
proc raiseRangeErrorF(i, a, b: float) {.compilerproc, noinline.} =
|
||||
sysFatal(RangeError, "value out of range: " & $i & " notin " & $a & " .. " & $b)
|
||||
sysFatal(RangeDefect, "value out of range: " & $i & " notin " & $a & " .. " & $b)
|
||||
|
||||
proc raiseRangeErrorU(i, a, b: uint64) {.compilerproc, noinline.} =
|
||||
# todo: better error reporting
|
||||
sysFatal(RangeError, "value out of range")
|
||||
sysFatal(RangeDefect, "value out of range")
|
||||
|
||||
proc raiseObjectConversionError() {.compilerproc, noinline.} =
|
||||
sysFatal(ObjectConversionError, "invalid object conversion")
|
||||
sysFatal(ObjectConversionDefect, "invalid object conversion")
|
||||
|
||||
proc chckIndx(i, a, b: int): int =
|
||||
if i >= a and i <= b:
|
||||
|
|
@ -63,24 +63,24 @@ proc chckRangeU(i, a, b: uint64): uint64 {.compilerproc.} =
|
|||
if i >= a and i <= b:
|
||||
return i
|
||||
else:
|
||||
sysFatal(RangeError, "value out of range")
|
||||
sysFatal(RangeDefect, "value out of range")
|
||||
|
||||
proc chckRangeF(x, a, b: float): float =
|
||||
if x >= a and x <= b:
|
||||
return x
|
||||
else:
|
||||
when hostOS == "standalone":
|
||||
sysFatal(RangeError, "value out of range")
|
||||
sysFatal(RangeDefect, "value out of range")
|
||||
else:
|
||||
sysFatal(RangeError, "value out of range: ", $x)
|
||||
sysFatal(RangeDefect, "value out of range: ", $x)
|
||||
|
||||
proc chckNil(p: pointer) =
|
||||
if p == nil:
|
||||
sysFatal(NilAccessError, "attempt to write to a nil address")
|
||||
sysFatal(NilAccessDefect, "attempt to write to a nil address")
|
||||
|
||||
proc chckNilDisp(p: pointer) {.compilerproc.} =
|
||||
if p == nil:
|
||||
sysFatal(NilAccessError, "cannot dispatch; dispatcher is nil")
|
||||
sysFatal(NilAccessDefect, "cannot dispatch; dispatcher is nil")
|
||||
|
||||
when not defined(nimV2):
|
||||
|
||||
|
|
@ -90,12 +90,12 @@ when not defined(nimV2):
|
|||
if x == subclass: return # optimized fast path
|
||||
while x != subclass:
|
||||
if x == nil:
|
||||
sysFatal(ObjectConversionError, "invalid object conversion")
|
||||
sysFatal(ObjectConversionDefect, "invalid object conversion")
|
||||
x = x.base
|
||||
|
||||
proc chckObjAsgn(a, b: PNimType) {.compilerproc, inline.} =
|
||||
if a != b:
|
||||
sysFatal(ObjectAssignmentError, "invalid object assignment")
|
||||
sysFatal(ObjectAssignmentDefect, "invalid object assignment")
|
||||
|
||||
type ObjCheckCache = array[0..1, PNimType]
|
||||
|
||||
|
|
@ -130,4 +130,4 @@ when not defined(nimV2):
|
|||
|
||||
when defined(nimV2):
|
||||
proc raiseObjectCaseTransition() {.compilerproc.} =
|
||||
sysFatal(FieldError, "assignment to discriminant changes object branch")
|
||||
sysFatal(FieldDefect, "assignment to discriminant changes object branch")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue