Change UnpackError with UnpackDefect (#14457)

* Change `UnpackError` with `UnpackDefect`

The deprecation warning for `UnpackError` exception raised by some
`inline` procedures in the Nim standard library propagates to the user
code. If the user code has a requirement for building without warnings
this is a problem for the successful execution of the tests. In order
to resolve this, all occurrences of `UnpackError` in the Nim code base
are changed to `UnpackDefect`. Only the type alias is retained to not
break other people's user code since `UnpackError` is exported type.

* Remove the catching of `UnpackDefect`

Defect exceptions should not be cached, because they indicate problem in
the API usage. The code in `nimblesocket.nim` is rewritten to first
check whether there is a value set into the `knownDomain` variable from
the `Option` type before usage.
This commit is contained in:
Ivan Bobev 2020-05-27 09:34:13 +03:00 • committed by GitHub
commit cc65ae6011
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 9 deletions

View file

@ -445,9 +445,10 @@ proc getSockDomain*(socket: SocketHandle): Domain =
if getsockname(socket, cast[ptr SockAddr](addr(name)),
addr(namelen)) == -1'i32:
raiseOSError(osLastError())
try:
result = toKnownDomain(name.sin6_family.cint).get()
except UnpackError:
let knownDomain = toKnownDomain(name.sin6_family.cint)
if knownDomain.isSome:
result = knownDomain.get()
else:
raise newException(IOError, "Unknown socket family in getSockDomain")
proc getAddrString*(sockAddr: ptr SockAddr): string =