diff options
-rw-r--r-- | lib/pure/nativesockets.nim | 7 | ||||
-rw-r--r-- | lib/pure/options.nim | 12 |
2 files changed, 10 insertions, 9 deletions
diff --git a/lib/pure/nativesockets.nim b/lib/pure/nativesockets.nim index 45ea93235..177476f41 100644 --- a/lib/pure/nativesockets.nim +++ b/lib/pure/nativesockets.nim @@ -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 = diff --git a/lib/pure/options.nim b/lib/pure/options.nim index 5e68f9146..d56cf4767 100644 --- a/lib/pure/options.nim +++ b/lib/pure/options.nim @@ -40,7 +40,7 @@ ## assert found.isSome and found.get() == 2 ## ## The `get` operation demonstrated above returns the underlying value, or -## raises `UnpackError` if there is no value. Note that `UnpackError` +## raises `UnpackDefect` if there is no value. Note that `UnpackDefect` ## inherits from `system.Defect`, and should therefore never be caught. ## Instead, rely on checking if the option contains a value with ## `isSome <#isSome,Option[T]>`_ and `isNone <#isNone,Option[T]>`_ procs. @@ -178,11 +178,11 @@ proc get*[T](self: Option[T]): lent T {.inline.} = a = some(42) b = none(string) assert a.get == 42 - doAssertRaises(UnpackError): + doAssertRaises(UnpackDefect): echo b.get if self.isNone: - raise newException(UnpackError, "Can't obtain a value from a `none`") + raise newException(UnpackDefect, "Can't obtain a value from a `none`") result = self.val proc get*[T](self: Option[T], otherwise: T): T {.inline.} = @@ -208,11 +208,11 @@ proc get*[T](self: var Option[T]): var T {.inline.} = a = some(42) b = none(string) assert a.get == 42 - doAssertRaises(UnpackError): + doAssertRaises(UnpackDefect): echo b.get if self.isNone: - raise newException(UnpackError, "Can't obtain a value from a `none`") + raise newException(UnpackDefect, "Can't obtain a value from a `none`") return self.val proc map*[T](self: Option[T], callback: proc (input: T)) {.inline.} = @@ -411,7 +411,7 @@ when isMainModule: check some("a").isSome test "none": - expect UnpackError: + expect UnpackDefect: discard none(int).get() check(none(int).isNone) check(not none(string).isSome) |