stdlib: documenation updates, the exception names have been changed

This commit is contained in:
Andreas Rumpf 2018-10-25 07:42:45 +02:00
commit 223e92b83a
15 changed files with 80 additions and 80 deletions

View file

@ -180,7 +180,7 @@ proc asyncSocket*(domain: Domain = AF_INET, typ: SockType = SOCK_STREAM,
protocol: Protocol = IPPROTO_TCP, protocol: Protocol = IPPROTO_TCP,
buffered = true): AsyncSocket = buffered = true): AsyncSocket =
## Initialises an AsyncSocket object. If a socket cannot be initialised ## Initialises an AsyncSocket object. If a socket cannot be initialised
## EOS is raised. ## OSError is raised.
result = newAsyncSocket() result = newAsyncSocket()
result.socket = socket(domain, typ, protocol, buffered) result.socket = socket(domain, typ, protocol, buffered)
result.proto = protocol result.proto = protocol
@ -476,7 +476,7 @@ proc recvLine*(s: AsyncSocket, line: var TaintedString): bool {.deprecated.} =
## if this function can only retrieve some data; it will save this data and ## if this function can only retrieve some data; it will save this data and
## add it to the result when a full line is retrieved. ## add it to the result when a full line is retrieved.
## ##
## Unlike ``sockets.recvLine`` this function will raise an EOS or ESSL ## Unlike ``sockets.recvLine`` this function will raise an OSError or SslError
## exception if an error occurs. ## exception if an error occurs.
## ##
## **Deprecated since version 0.9.2**: This function has been deprecated in ## **Deprecated since version 0.9.2**: This function has been deprecated in
@ -512,7 +512,7 @@ proc readLine*(s: AsyncSocket, line: var TaintedString): bool =
## retrieved or the socket has been disconnected in which case ``line`` will ## retrieved or the socket has been disconnected in which case ``line`` will
## be set to "". ## be set to "".
## ##
## This function will raise an EOS exception when a socket error occurs. ## This function will raise an OSError exception when a socket error occurs.
setLen(line.string, 0) setLen(line.string, 0)
var dataReceived = "".TaintedString var dataReceived = "".TaintedString
var ret = s.socket.readLineAsync(dataReceived) var ret = s.socket.readLineAsync(dataReceived)

View file

@ -23,7 +23,7 @@
## ##
## SSL is supported through the OpenSSL library. This support can be activated ## SSL is supported through the OpenSSL library. This support can be activated
## by compiling with the ``-d:ssl`` switch. When an SSL socket is used it will ## by compiling with the ``-d:ssl`` switch. When an SSL socket is used it will
## raise ESSL exceptions when SSL errors occur. ## raise SslError exceptions when SSL errors occur.
## ##
## Asynchronous sockets are supported, however a better alternative is to use ## Asynchronous sockets are supported, however a better alternative is to use
## the `asyncio <asyncio.html>`_ module. ## the `asyncio <asyncio.html>`_ module.
@ -262,7 +262,7 @@ proc socket*(domain: Domain = AF_INET, typ: SockType = SOCK_STREAM,
protocol: Protocol = IPPROTO_TCP, buffered = true): Socket = protocol: Protocol = IPPROTO_TCP, buffered = true): Socket =
## Creates a new socket; returns `InvalidSocket` if an error occurs. ## Creates a new socket; returns `InvalidSocket` if an error occurs.
# TODO: Perhaps this should just raise EOS when an error occurs. # TODO: Perhaps this should just raise OSError when an error occurs.
when defined(Windows): when defined(Windows):
result = newTSocket(winlean.socket(cint(domain), cint(typ), cint(protocol)), buffered) result = newTSocket(winlean.socket(cint(domain), cint(typ), cint(protocol)), buffered)
else: else:
@ -422,7 +422,7 @@ proc parseIp4*(s: string): BiggestInt =
## ##
## This is equivalent to `inet_ntoa`:idx:. ## This is equivalent to `inet_ntoa`:idx:.
## ##
## Raises EInvalidValue in case of an error. ## Raises ValueError in case of an error.
var a, b, c, d: int var a, b, c, d: int
var i = 0 var i = 0
var j = parseInt(s, a, i) var j = parseInt(s, a, i)
@ -543,7 +543,7 @@ proc acceptAddr*(server: Socket, client: var Socket, address: var string) {.
## If ``server`` is non-blocking then this function returns immediately, and ## If ``server`` is non-blocking then this function returns immediately, and
## if there are no connections queued the returned socket will be ## if there are no connections queued the returned socket will be
## ``InvalidSocket``. ## ``InvalidSocket``.
## This function will raise EOS if an error occurs. ## This function will raise OSError if an error occurs.
## ##
## The resulting client will inherit any properties of the server socket. For ## The resulting client will inherit any properties of the server socket. For
## example: whether the socket is buffered or not. ## example: whether the socket is buffered or not.
@ -664,7 +664,7 @@ proc close*(socket: Socket) =
discard winlean.closesocket(socket.fd) discard winlean.closesocket(socket.fd)
else: else:
discard posix.close(socket.fd) discard posix.close(socket.fd)
# TODO: These values should not be discarded. An EOS should be raised. # TODO: These values should not be discarded. An OSError should be raised.
# http://stackoverflow.com/questions/12463473/what-happens-if-you-call-close-on-a-bsd-socket-multiple-times # http://stackoverflow.com/questions/12463473/what-happens-if-you-call-close-on-a-bsd-socket-multiple-times
when defined(ssl): when defined(ssl):
if socket.isSSL: if socket.isSSL:
@ -920,7 +920,7 @@ when defined(ssl):
## Returns ``False`` whenever the socket is not yet ready for a handshake, ## Returns ``False`` whenever the socket is not yet ready for a handshake,
## ``True`` whenever handshake completed successfully. ## ``True`` whenever handshake completed successfully.
## ##
## A ESSL error is raised on any other errors. ## A SslError error is raised on any other errors.
result = true result = true
if socket.isSSL: if socket.isSSL:
var ret = SSLConnect(socket.sslHandle) var ret = SSLConnect(socket.sslHandle)
@ -946,7 +946,7 @@ when defined(ssl):
## Determines whether a handshake has occurred between a client (``socket``) ## Determines whether a handshake has occurred between a client (``socket``)
## and the server that ``socket`` is connected to. ## and the server that ``socket`` is connected to.
## ##
## Throws ESSL if ``socket`` is not an SSL socket. ## Throws SslError if ``socket`` is not an SSL socket.
if socket.isSSL: if socket.isSSL:
return not socket.sslNoHandshake return not socket.sslNoHandshake
else: else:
@ -1215,7 +1215,7 @@ proc recv*(socket: Socket, data: var string, size: int, timeout = -1): int =
## ##
## When 0 is returned the socket's connection has been closed. ## When 0 is returned the socket's connection has been closed.
## ##
## This function will throw an EOS exception when an error occurs. A value ## This function will throw an OSError exception when an error occurs. A value
## lower than 0 is never returned. ## lower than 0 is never returned.
## ##
## A timeout may be specified in milliseconds, if enough data is not received ## A timeout may be specified in milliseconds, if enough data is not received
@ -1273,7 +1273,7 @@ proc recvLine*(socket: Socket, line: var TaintedString, timeout = -1): bool {.
## will be set to it. ## will be set to it.
## ##
## ``True`` is returned if data is available. ``False`` suggests an ## ``True`` is returned if data is available. ``False`` suggests an
## error, EOS exceptions are not raised and ``False`` is simply returned ## error, OSError exceptions are not raised and ``False`` is simply returned
## instead. ## instead.
## ##
## If the socket is disconnected, ``line`` will be set to ``""`` and ``True`` ## If the socket is disconnected, ``line`` will be set to ``""`` and ``True``
@ -1321,7 +1321,7 @@ proc readLine*(socket: Socket, line: var TaintedString, timeout = -1) {.
## ##
## If the socket is disconnected, ``line`` will be set to ``""``. ## If the socket is disconnected, ``line`` will be set to ``""``.
## ##
## An EOS exception will be raised in the case of a socket error. ## An OSError exception will be raised in the case of a socket error.
## ##
## A timeout can be specified in milliseconds, if data is not received within ## A timeout can be specified in milliseconds, if data is not received within
## the specified time an ETimeout exception will be raised. ## the specified time an ETimeout exception will be raised.
@ -1394,7 +1394,7 @@ proc readLineAsync*(socket: Socket,
## * If some data has been retrieved; ``ReadPartialLine`` is returned. ## * If some data has been retrieved; ``ReadPartialLine`` is returned.
## * If the socket has been disconnected; ``ReadDisconnected`` is returned. ## * If the socket has been disconnected; ``ReadDisconnected`` is returned.
## * If no data could be retrieved; ``ReadNone`` is returned. ## * If no data could be retrieved; ``ReadNone`` is returned.
## * If call to ``recv`` failed; **an EOS exception is raised.** ## * If call to ``recv`` failed; **an OSError exception is raised.**
setLen(line.string, 0) setLen(line.string, 0)
template errorOrNone = template errorOrNone =
@ -1421,7 +1421,7 @@ proc readLineAsync*(socket: Socket,
proc recv*(socket: Socket): TaintedString {.tags: [ReadIOEffect], deprecated.} = proc recv*(socket: Socket): TaintedString {.tags: [ReadIOEffect], deprecated.} =
## receives all the available data from the socket. ## receives all the available data from the socket.
## Socket errors will result in an ``EOS`` error. ## Socket errors will result in an ``OSError`` error.
## If socket is not a connectionless socket and socket is not connected ## If socket is not a connectionless socket and socket is not connected
## ``""`` will be returned. ## ``""`` will be returned.
## ##
@ -1470,7 +1470,7 @@ proc recvAsync*(socket: Socket, s: var TaintedString): bool {.
tags: [ReadIOEffect], deprecated.} = tags: [ReadIOEffect], deprecated.} =
## receives all the data from a non-blocking socket. If socket is non-blocking ## receives all the data from a non-blocking socket. If socket is non-blocking
## and there are no messages available, `False` will be returned. ## and there are no messages available, `False` will be returned.
## Other socket errors will result in an ``EOS`` error. ## Other socket errors will result in an ``OSError`` error.
## If socket is not a connectionless socket and socket is not connected ## If socket is not a connectionless socket and socket is not connected
## ``s`` will be set to ``""``. ## ``s`` will be set to ``""``.
## ##
@ -1547,7 +1547,7 @@ proc recvFromAsync*(socket: Socket, data: var string, length: int,
address: var string, port: var Port, address: var string, port: var Port,
flags = 0'i32): bool {.tags: [ReadIOEffect].} = flags = 0'i32): bool {.tags: [ReadIOEffect].} =
## Variant of ``recvFrom`` for non-blocking sockets. Unlike ``recvFrom``, ## Variant of ``recvFrom`` for non-blocking sockets. Unlike ``recvFrom``,
## this function will raise an EOS error whenever a socket error occurs. ## this function will raise an OSError error whenever a socket error occurs.
## ##
## If there is no data to be read from the socket ``False`` will be returned. ## If there is no data to be read from the socket ``False`` will be returned.
result = true result = true
@ -1622,7 +1622,7 @@ proc sendAsync*(socket: Socket, data: string): int {.tags: [WriteIOEffect].} =
## returns the amount of bytes of ``data`` that was successfully sent. This ## returns the amount of bytes of ``data`` that was successfully sent. This
## number may not always be the length of ``data`` but typically is. ## number may not always be the length of ``data`` but typically is.
## ##
## An EOS (or ESSL if socket is an SSL socket) exception is raised if an error ## An OSError (or SslError if socket is an SSL socket) exception is raised if an error
## occurs. ## occurs.
result = send(socket, cstring(data), data.len) result = send(socket, cstring(data), data.len)
when defined(ssl): when defined(ssl):
@ -1656,7 +1656,7 @@ proc sendAsync*(socket: Socket, data: string): int {.tags: [WriteIOEffect].} =
proc trySend*(socket: Socket, data: string): bool {.tags: [WriteIOEffect].} = proc trySend*(socket: Socket, data: string): bool {.tags: [WriteIOEffect].} =
## safe alternative to ``send``. Does not raise an EOS when an error occurs, ## safe alternative to ``send``. Does not raise an OSError when an error occurs,
## and instead returns ``false`` on failure. ## and instead returns ``false`` on failure.
result = send(socket, cstring(data), data.len) == data.len result = send(socket, cstring(data), data.len) == data.len

View file

@ -105,7 +105,7 @@ proc add*(monitor: FSMonitor, target: string,
proc del*(monitor: FSMonitor, wd: cint) = proc del*(monitor: FSMonitor, wd: cint) =
## Removes watched directory or file as specified by ``wd`` from ``monitor``. ## Removes watched directory or file as specified by ``wd`` from ``monitor``.
## ##
## If ``wd`` is not a part of ``monitor`` an EOS error is raised. ## If ``wd`` is not a part of ``monitor`` an OSError error is raised.
if inotifyRmWatch(monitor.fd, wd) < 0: if inotifyRmWatch(monitor.fd, wd) < 0:
raiseOSError(osLastError()) raiseOSError(osLastError())

View file

@ -599,7 +599,7 @@ proc listen*(socket: AsyncSocket, backlog = SOMAXCONN) {.tags: [ReadIOEffect].}
## ``Backlog`` specifies the maximum length of the ## ``Backlog`` specifies the maximum length of the
## queue of pending connections. ## queue of pending connections.
## ##
## Raises an EOS error upon failure. ## Raises an OSError error upon failure.
if listen(socket.fd, backlog) < 0'i32: raiseOSError(osLastError()) if listen(socket.fd, backlog) < 0'i32: raiseOSError(osLastError())
proc bindAddr*(socket: AsyncSocket, port = Port(0), address = "") {. proc bindAddr*(socket: AsyncSocket, port = Port(0), address = "") {.

View file

@ -377,7 +377,7 @@ proc colorNameCmp(x: tuple[name: string, col: Color], y: string): int =
proc parseColor*(name: string): Color = proc parseColor*(name: string): Color =
## parses `name` to a color value. If no valid color could be ## parses `name` to a color value. If no valid color could be
## parsed ``EInvalidValue`` is raised. Case insensitive. ## parsed ``ValueError`` is raised. Case insensitive.
if name[0] == '#': if name[0] == '#':
result = Color(parseHexInt(name)) result = Color(parseHexInt(name))
else: else:

View file

@ -302,7 +302,7 @@ proc getCurrentEncoding*(): string =
proc open*(destEncoding = "UTF-8", srcEncoding = "CP1252"): EncodingConverter = proc open*(destEncoding = "UTF-8", srcEncoding = "CP1252"): EncodingConverter =
## opens a converter that can convert from `srcEncoding` to `destEncoding`. ## opens a converter that can convert from `srcEncoding` to `destEncoding`.
## Raises `EIO` if it cannot fulfill the request. ## Raises `IOError` if it cannot fulfill the request.
when not defined(windows): when not defined(windows):
result = iconvOpen(destEncoding, srcEncoding) result = iconvOpen(destEncoding, srcEncoding)
if result == nil: if result == nil:

View file

@ -254,12 +254,12 @@ proc loadAny(s: Stream, a: Any, t: var Table[BiggestInt, pointer]) =
close(p) close(p)
proc load*[T](s: Stream, data: var T) = proc load*[T](s: Stream, data: var T) =
## loads `data` from the stream `s`. Raises `EIO` in case of an error. ## loads `data` from the stream `s`. Raises `IOError` in case of an error.
var tab = initTable[BiggestInt, pointer]() var tab = initTable[BiggestInt, pointer]()
loadAny(s, toAny(data), tab) loadAny(s, toAny(data), tab)
proc store*[T](s: Stream, data: T) = proc store*[T](s: Stream, data: T) =
## stores `data` into the stream `s`. Raises `EIO` in case of an error. ## stores `data` into the stream `s`. Raises `IOError` in case of an error.
var stored = initIntSet() var stored = initIntSet()
var d: T var d: T
shallowCopy(d, data) shallowCopy(d, data)

View file

@ -90,7 +90,7 @@ proc unmapMem*(f: var MemFile, p: pointer, size: int) =
proc open*(filename: string, mode: FileMode = fmRead, proc open*(filename: string, mode: FileMode = fmRead,
mappedSize = -1, offset = 0, newFileSize = -1, mappedSize = -1, offset = 0, newFileSize = -1,
allowRemap = false): MemFile = allowRemap = false): MemFile =
## opens a memory mapped file. If this fails, ``EOS`` is raised. ## opens a memory mapped file. If this fails, ``OSError`` is raised.
## ##
## ``newFileSize`` can only be set if the file does not exist and is opened ## ``newFileSize`` can only be set if the file does not exist and is opened
## with write access (e.g., with fmReadWrite). ## with write access (e.g., with fmReadWrite).
@ -141,7 +141,7 @@ proc open*(filename: string, mode: FileMode = fmRead,
if result.mapHandle != 0: discard closeHandle(result.mapHandle) if result.mapHandle != 0: discard closeHandle(result.mapHandle)
raiseOSError(errCode) raiseOSError(errCode)
# return false # return false
#raise newException(EIO, msg) #raise newException(IOError, msg)
template callCreateFile(winApiProc, filename): untyped = template callCreateFile(winApiProc, filename): untyped =
winApiProc( winApiProc(
@ -465,7 +465,7 @@ proc mmsWriteData(s: Stream, buffer: pointer, bufLen: int) =
proc newMemMapFileStream*(filename: string, mode: FileMode = fmRead, fileSize: int = -1): proc newMemMapFileStream*(filename: string, mode: FileMode = fmRead, fileSize: int = -1):
MemMapFileStream = MemMapFileStream =
## creates a new stream from the file named `filename` with the mode `mode`. ## creates a new stream from the file named `filename` with the mode `mode`.
## Raises ## `EOS` if the file cannot be opened. See the `system ## Raises ## `OSError` if the file cannot be opened. See the `system
## <system.html>`_ module for a list of available FileMode enums. ## <system.html>`_ module for a list of available FileMode enums.
## ``fileSize`` can only be set if the file does not exist and is opened ## ``fileSize`` can only be set if the file does not exist and is opened
## with write access (e.g., with fmReadWrite). ## with write access (e.g., with fmReadWrite).

View file

@ -221,7 +221,7 @@ proc close*(socket: SocketHandle) =
discard winlean.closesocket(socket) discard winlean.closesocket(socket)
else: else:
discard posix.close(socket) discard posix.close(socket)
# TODO: These values should not be discarded. An EOS should be raised. # TODO: These values should not be discarded. An OSError should be raised.
# http://stackoverflow.com/questions/12463473/what-happens-if-you-call-close-on-a-bsd-socket-multiple-times # http://stackoverflow.com/questions/12463473/what-happens-if-you-call-close-on-a-bsd-socket-multiple-times
proc bindAddr*(socket: SocketHandle, name: ptr SockAddr, namelen: SockLen): cint = proc bindAddr*(socket: SocketHandle, name: ptr SockAddr, namelen: SockLen): cint =
@ -594,7 +594,7 @@ proc setSockOptInt*(socket: SocketHandle, level, optname, optval: int) {.
proc setBlocking*(s: SocketHandle, blocking: bool) = proc setBlocking*(s: SocketHandle, blocking: bool) =
## Sets blocking mode on socket. ## Sets blocking mode on socket.
## ##
## Raises EOS on error. ## Raises OSError on error.
when useWinVersion: when useWinVersion:
var mode = clong(ord(not blocking)) # 1 for non-blocking, 0 for blocking var mode = clong(ord(not blocking)) # 1 for non-blocking, 0 for blocking
if ioctlsocket(s, FIONBIO, addr(mode)) == -1: if ioctlsocket(s, FIONBIO, addr(mode)) == -1:

View file

@ -210,7 +210,7 @@ proc newSocket*(fd: SocketHandle, domain: Domain = AF_INET,
proc newSocket*(domain, sockType, protocol: cint, buffered = true): Socket = proc newSocket*(domain, sockType, protocol: cint, buffered = true): Socket =
## Creates a new socket. ## Creates a new socket.
## ##
## If an error occurs EOS will be raised. ## If an error occurs OSError will be raised.
let fd = createNativeSocket(domain, sockType, protocol) let fd = createNativeSocket(domain, sockType, protocol)
if fd == osInvalidSocket: if fd == osInvalidSocket:
raiseOSError(osLastError()) raiseOSError(osLastError())
@ -221,7 +221,7 @@ proc newSocket*(domain: Domain = AF_INET, sockType: SockType = SOCK_STREAM,
protocol: Protocol = IPPROTO_TCP, buffered = true): Socket = protocol: Protocol = IPPROTO_TCP, buffered = true): Socket =
## Creates a new socket. ## Creates a new socket.
## ##
## If an error occurs EOS will be raised. ## If an error occurs OSError will be raised.
let fd = createNativeSocket(domain, sockType, protocol) let fd = createNativeSocket(domain, sockType, protocol)
if fd == osInvalidSocket: if fd == osInvalidSocket:
raiseOSError(osLastError()) raiseOSError(osLastError())
@ -229,7 +229,7 @@ proc newSocket*(domain: Domain = AF_INET, sockType: SockType = SOCK_STREAM,
proc parseIPv4Address(addressStr: string): IpAddress = proc parseIPv4Address(addressStr: string): IpAddress =
## Parses IPv4 adresses ## Parses IPv4 adresses
## Raises EInvalidValue on errors ## Raises ValueError on errors
var var
byteCount = 0 byteCount = 0
currentByte:uint16 = 0 currentByte:uint16 = 0
@ -263,7 +263,7 @@ proc parseIPv4Address(addressStr: string): IpAddress =
proc parseIPv6Address(addressStr: string): IpAddress = proc parseIPv6Address(addressStr: string): IpAddress =
## Parses IPv6 adresses ## Parses IPv6 adresses
## Raises EInvalidValue on errors ## Raises ValueError on errors
result.family = IpAddressFamily.IPv6 result.family = IpAddressFamily.IPv6
if addressStr.len < 2: if addressStr.len < 2:
raise newException(ValueError, "Invalid IP Address") raise newException(ValueError, "Invalid IP Address")
@ -384,7 +384,7 @@ proc parseIPv6Address(addressStr: string): IpAddress =
proc parseIpAddress*(addressStr: string): IpAddress = proc parseIpAddress*(addressStr: string): IpAddress =
## Parses an IP address ## Parses an IP address
## Raises EInvalidValue on error ## Raises ValueError on error
if addressStr.len == 0: if addressStr.len == 0:
raise newException(ValueError, "IP Address string is empty") raise newException(ValueError, "IP Address string is empty")
if addressStr.contains(':'): if addressStr.contains(':'):
@ -746,7 +746,7 @@ proc listen*(socket: Socket, backlog = SOMAXCONN) {.tags: [ReadIOEffect].} =
## ``Backlog`` specifies the maximum length of the ## ``Backlog`` specifies the maximum length of the
## queue of pending connections. ## queue of pending connections.
## ##
## Raises an EOS error upon failure. ## Raises an OSError error upon failure.
if nativesockets.listen(socket.fd, backlog) < 0'i32: if nativesockets.listen(socket.fd, backlog) < 0'i32:
raiseOSError(osLastError()) raiseOSError(osLastError())
@ -777,7 +777,7 @@ proc acceptAddr*(server: Socket, client: var Socket, address: var string,
## Blocks until a connection is being made from a client. When a connection ## Blocks until a connection is being made from a client. When a connection
## is made sets ``client`` to the client socket and ``address`` to the address ## is made sets ``client`` to the client socket and ``address`` to the address
## of the connecting client. ## of the connecting client.
## This function will raise EOS if an error occurs. ## This function will raise OSError if an error occurs.
## ##
## The resulting client will inherit any properties of the server socket. For ## The resulting client will inherit any properties of the server socket. For
## example: whether the socket is buffered or not. ## example: whether the socket is buffered or not.
@ -983,7 +983,7 @@ when defined(ssl):
## Returns ``False`` whenever the socket is not yet ready for a handshake, ## Returns ``False`` whenever the socket is not yet ready for a handshake,
## ``True`` whenever handshake completed successfully. ## ``True`` whenever handshake completed successfully.
## ##
## A ESSL error is raised on any other errors. ## A SslError error is raised on any other errors.
## ##
## **Note:** This procedure is deprecated since version 0.14.0. ## **Note:** This procedure is deprecated since version 0.14.0.
result = true result = true
@ -1011,7 +1011,7 @@ when defined(ssl):
## Determines whether a handshake has occurred between a client (``socket``) ## Determines whether a handshake has occurred between a client (``socket``)
## and the server that ``socket`` is connected to. ## and the server that ``socket`` is connected to.
## ##
## Throws ESSL if ``socket`` is not an SSL socket. ## Throws SslError if ``socket`` is not an SSL socket.
if socket.isSSL: if socket.isSSL:
return not socket.sslNoHandshake return not socket.sslNoHandshake
else: else:
@ -1203,7 +1203,7 @@ proc recv*(socket: Socket, size: int, timeout = -1,
## ##
## When ``""`` is returned the socket's connection has been closed. ## When ``""`` is returned the socket's connection has been closed.
## ##
## This function will throw an EOS exception when an error occurs. ## This function will throw an OSError exception when an error occurs.
## ##
## A timeout may be specified in milliseconds, if enough data is not received ## A timeout may be specified in milliseconds, if enough data is not received
## within the time specified an ETimeout exception will be raised. ## within the time specified an ETimeout exception will be raised.
@ -1244,7 +1244,7 @@ proc readLine*(socket: Socket, line: var TaintedString, timeout = -1,
## ##
## If the socket is disconnected, ``line`` will be set to ``""``. ## If the socket is disconnected, ``line`` will be set to ``""``.
## ##
## An EOS exception will be raised in the case of a socket error. ## An OSError exception will be raised in the case of a socket error.
## ##
## A timeout can be specified in milliseconds, if data is not received within ## A timeout can be specified in milliseconds, if data is not received within
## the specified time an ETimeout exception will be raised. ## the specified time an ETimeout exception will be raised.
@ -1299,7 +1299,7 @@ proc recvLine*(socket: Socket, timeout = -1,
## ##
## If the socket is disconnected, the result will be set to ``""``. ## If the socket is disconnected, the result will be set to ``""``.
## ##
## An EOS exception will be raised in the case of a socket error. ## An OSError exception will be raised in the case of a socket error.
## ##
## A timeout can be specified in milliseconds, if data is not received within ## A timeout can be specified in milliseconds, if data is not received within
## the specified time an ETimeout exception will be raised. ## the specified time an ETimeout exception will be raised.
@ -1317,7 +1317,7 @@ proc recvFrom*(socket: Socket, data: var string, length: int,
## Receives data from ``socket``. This function should normally be used with ## Receives data from ``socket``. This function should normally be used with
## connection-less sockets (UDP sockets). ## connection-less sockets (UDP sockets).
## ##
## If an error occurs an EOS exception will be raised. Otherwise the return ## If an error occurs an OSError exception will be raised. Otherwise the return
## value will be the length of data received. ## value will be the length of data received.
## ##
## **Warning:** This function does not yet have a buffered implementation, ## **Warning:** This function does not yet have a buffered implementation,
@ -1390,7 +1390,7 @@ template `&=`*(socket: Socket; data: typed) =
send(socket, data) send(socket, data)
proc trySend*(socket: Socket, data: string): bool {.tags: [WriteIOEffect].} = proc trySend*(socket: Socket, data: string): bool {.tags: [WriteIOEffect].} =
## Safe alternative to ``send``. Does not raise an EOS when an error occurs, ## Safe alternative to ``send``. Does not raise an OSError when an error occurs,
## and instead returns ``false`` on failure. ## and instead returns ``false`` on failure.
result = send(socket, cstring(data), data.len) == data.len result = send(socket, cstring(data), data.len) == data.len

View file

@ -121,7 +121,7 @@ proc startProcess*(command: string,
## invocation if possible as it leads to non portable software. ## invocation if possible as it leads to non portable software.
## ##
## Return value: The newly created process object. Nil is never returned, ## Return value: The newly created process object. Nil is never returned,
## but ``EOS`` is raised in case of an error. ## but ``OSError`` is raised in case of an error.
proc startCmd*(command: string, options: set[ProcessOption] = { proc startCmd*(command: string, options: set[ProcessOption] = {
poStdErrToStdOut, poUsePath}): Process {. poStdErrToStdOut, poUsePath}): Process {.

View file

@ -267,7 +267,7 @@ proc parseBiggestInt*(s: string, number: var BiggestInt, start = 0): int {.
rtl, extern: "npuParseBiggestInt", noSideEffect.} = rtl, extern: "npuParseBiggestInt", noSideEffect.} =
## parses an integer starting at `start` and stores the value into `number`. ## parses an integer starting at `start` and stores the value into `number`.
## Result is the number of processed chars or 0 if there is no integer. ## Result is the number of processed chars or 0 if there is no integer.
## `EOverflow` is raised if an overflow occurs. ## `OverflowError` is raised if an overflow occurs.
var res: BiggestInt var res: BiggestInt
# use 'res' for exception safety (don't write to 'number' in case of an # use 'res' for exception safety (don't write to 'number' in case of an
# overflow exception): # overflow exception):

View file

@ -1342,7 +1342,7 @@ when not defined(js):
subs: varargs[tuple[pattern: Peg, repl: string]]) {. subs: varargs[tuple[pattern: Peg, repl: string]]) {.
rtl, extern: "npegs$1".} = rtl, extern: "npegs$1".} =
## reads in the file `infile`, performs a parallel replacement (calls ## reads in the file `infile`, performs a parallel replacement (calls
## `parallelReplace`) and writes back to `outfile`. Raises ``EIO`` if an ## `parallelReplace`) and writes back to `outfile`. Raises ``IOError`` if an
## error occurs. This is supposed to be used for quick scripting. ## error occurs. This is supposed to be used for quick scripting.
## ##
## **Note**: this proc does not exist while using the JS backend. ## **Note**: this proc does not exist while using the JS backend.

View file

@ -157,112 +157,112 @@ proc peek[T](s: Stream, result: var T) =
raise newEIO("cannot read from stream") raise newEIO("cannot read from stream")
proc readChar*(s: Stream): char = proc readChar*(s: Stream): char =
## reads a char from the stream `s`. Raises `EIO` if an error occurred. ## reads a char from the stream `s`. Raises `IOError` if an error occurred.
## Returns '\\0' as an EOF marker. ## Returns '\\0' as an EOF marker.
if readData(s, addr(result), sizeof(result)) != 1: result = '\0' if readData(s, addr(result), sizeof(result)) != 1: result = '\0'
proc peekChar*(s: Stream): char = proc peekChar*(s: Stream): char =
## peeks a char from the stream `s`. Raises `EIO` if an error occurred. ## peeks a char from the stream `s`. Raises `IOError` if an error occurred.
## Returns '\\0' as an EOF marker. ## Returns '\\0' as an EOF marker.
if peekData(s, addr(result), sizeof(result)) != 1: result = '\0' if peekData(s, addr(result), sizeof(result)) != 1: result = '\0'
proc readBool*(s: Stream): bool = proc readBool*(s: Stream): bool =
## reads a bool from the stream `s`. Raises `EIO` if an error occurred. ## reads a bool from the stream `s`. Raises `IOError` if an error occurred.
read(s, result) read(s, result)
proc peekBool*(s: Stream): bool = proc peekBool*(s: Stream): bool =
## peeks a bool from the stream `s`. Raises `EIO` if an error occurred. ## peeks a bool from the stream `s`. Raises `IOError` if an error occurred.
peek(s, result) peek(s, result)
proc readInt8*(s: Stream): int8 = proc readInt8*(s: Stream): int8 =
## reads an int8 from the stream `s`. Raises `EIO` if an error occurred. ## reads an int8 from the stream `s`. Raises `IOError` if an error occurred.
read(s, result) read(s, result)
proc peekInt8*(s: Stream): int8 = proc peekInt8*(s: Stream): int8 =
## peeks an int8 from the stream `s`. Raises `EIO` if an error occurred. ## peeks an int8 from the stream `s`. Raises `IOError` if an error occurred.
peek(s, result) peek(s, result)
proc readInt16*(s: Stream): int16 = proc readInt16*(s: Stream): int16 =
## reads an int16 from the stream `s`. Raises `EIO` if an error occurred. ## reads an int16 from the stream `s`. Raises `IOError` if an error occurred.
read(s, result) read(s, result)
proc peekInt16*(s: Stream): int16 = proc peekInt16*(s: Stream): int16 =
## peeks an int16 from the stream `s`. Raises `EIO` if an error occurred. ## peeks an int16 from the stream `s`. Raises `IOError` if an error occurred.
peek(s, result) peek(s, result)
proc readInt32*(s: Stream): int32 = proc readInt32*(s: Stream): int32 =
## reads an int32 from the stream `s`. Raises `EIO` if an error occurred. ## reads an int32 from the stream `s`. Raises `IOError` if an error occurred.
read(s, result) read(s, result)
proc peekInt32*(s: Stream): int32 = proc peekInt32*(s: Stream): int32 =
## peeks an int32 from the stream `s`. Raises `EIO` if an error occurred. ## peeks an int32 from the stream `s`. Raises `IOError` if an error occurred.
peek(s, result) peek(s, result)
proc readInt64*(s: Stream): int64 = proc readInt64*(s: Stream): int64 =
## reads an int64 from the stream `s`. Raises `EIO` if an error occurred. ## reads an int64 from the stream `s`. Raises `IOError` if an error occurred.
read(s, result) read(s, result)
proc peekInt64*(s: Stream): int64 = proc peekInt64*(s: Stream): int64 =
## peeks an int64 from the stream `s`. Raises `EIO` if an error occurred. ## peeks an int64 from the stream `s`. Raises `IOError` if an error occurred.
peek(s, result) peek(s, result)
proc readUint8*(s: Stream): uint8 = proc readUint8*(s: Stream): uint8 =
## reads an uint8 from the stream `s`. Raises `EIO` if an error occurred. ## reads an uint8 from the stream `s`. Raises `IOError` if an error occurred.
read(s, result) read(s, result)
proc peekUint8*(s: Stream): uint8 = proc peekUint8*(s: Stream): uint8 =
## peeks an uint8 from the stream `s`. Raises `EIO` if an error occurred. ## peeks an uint8 from the stream `s`. Raises `IOError` if an error occurred.
peek(s, result) peek(s, result)
proc readUint16*(s: Stream): uint16 = proc readUint16*(s: Stream): uint16 =
## reads an uint16 from the stream `s`. Raises `EIO` if an error occurred. ## reads an uint16 from the stream `s`. Raises `IOError` if an error occurred.
read(s, result) read(s, result)
proc peekUint16*(s: Stream): uint16 = proc peekUint16*(s: Stream): uint16 =
## peeks an uint16 from the stream `s`. Raises `EIO` if an error occurred. ## peeks an uint16 from the stream `s`. Raises `IOError` if an error occurred.
peek(s, result) peek(s, result)
proc readUint32*(s: Stream): uint32 = proc readUint32*(s: Stream): uint32 =
## reads an uint32 from the stream `s`. Raises `EIO` if an error occurred. ## reads an uint32 from the stream `s`. Raises `IOError` if an error occurred.
read(s, result) read(s, result)
proc peekUint32*(s: Stream): uint32 = proc peekUint32*(s: Stream): uint32 =
## peeks an uint32 from the stream `s`. Raises `EIO` if an error occurred. ## peeks an uint32 from the stream `s`. Raises `IOError` if an error occurred.
peek(s, result) peek(s, result)
proc readUint64*(s: Stream): uint64 = proc readUint64*(s: Stream): uint64 =
## reads an uint64 from the stream `s`. Raises `EIO` if an error occurred. ## reads an uint64 from the stream `s`. Raises `IOError` if an error occurred.
read(s, result) read(s, result)
proc peekUint64*(s: Stream): uint64 = proc peekUint64*(s: Stream): uint64 =
## peeks an uint64 from the stream `s`. Raises `EIO` if an error occurred. ## peeks an uint64 from the stream `s`. Raises `IOError` if an error occurred.
peek(s, result) peek(s, result)
proc readFloat32*(s: Stream): float32 = proc readFloat32*(s: Stream): float32 =
## reads a float32 from the stream `s`. Raises `EIO` if an error occurred. ## reads a float32 from the stream `s`. Raises `IOError` if an error occurred.
read(s, result) read(s, result)
proc peekFloat32*(s: Stream): float32 = proc peekFloat32*(s: Stream): float32 =
## peeks a float32 from the stream `s`. Raises `EIO` if an error occurred. ## peeks a float32 from the stream `s`. Raises `IOError` if an error occurred.
peek(s, result) peek(s, result)
proc readFloat64*(s: Stream): float64 = proc readFloat64*(s: Stream): float64 =
## reads a float64 from the stream `s`. Raises `EIO` if an error occurred. ## reads a float64 from the stream `s`. Raises `IOError` if an error occurred.
read(s, result) read(s, result)
proc peekFloat64*(s: Stream): float64 = proc peekFloat64*(s: Stream): float64 =
## peeks a float64 from the stream `s`. Raises `EIO` if an error occurred. ## peeks a float64 from the stream `s`. Raises `IOError` if an error occurred.
peek(s, result) peek(s, result)
proc readStr*(s: Stream, length: int): TaintedString = proc readStr*(s: Stream, length: int): TaintedString =
## reads a string of length `length` from the stream `s`. Raises `EIO` if ## reads a string of length `length` from the stream `s`. Raises `IOError` if
## an error occurred. ## an error occurred.
result = newString(length).TaintedString result = newString(length).TaintedString
var L = readData(s, cstring(result), length) var L = readData(s, cstring(result), length)
if L != length: setLen(result.string, L) if L != length: setLen(result.string, L)
proc peekStr*(s: Stream, length: int): TaintedString = proc peekStr*(s: Stream, length: int): TaintedString =
## peeks a string of length `length` from the stream `s`. Raises `EIO` if ## peeks a string of length `length` from the stream `s`. Raises `IOError` if
## an error occurred. ## an error occurred.
result = newString(length).TaintedString result = newString(length).TaintedString
var L = peekData(s, cstring(result), length) var L = peekData(s, cstring(result), length)
@ -301,7 +301,7 @@ proc peekLine*(s: Stream, line: var TaintedString): bool =
proc readLine*(s: Stream): TaintedString = proc readLine*(s: Stream): TaintedString =
## Reads a line from a stream `s`. Note: This is not very efficient. Raises ## Reads a line from a stream `s`. Note: This is not very efficient. Raises
## `EIO` if an error occurred. ## `IOError` if an error occurred.
result = TaintedString"" result = TaintedString""
if s.atEnd: if s.atEnd:
raise newEIO("cannot read from stream") raise newEIO("cannot read from stream")
@ -317,7 +317,7 @@ proc readLine*(s: Stream): TaintedString =
proc peekLine*(s: Stream): TaintedString = proc peekLine*(s: Stream): TaintedString =
## Peeks a line from a stream `s`. Note: This is not very efficient. Raises ## Peeks a line from a stream `s`. Note: This is not very efficient. Raises
## `EIO` if an error occurred. ## `IOError` if an error occurred.
let pos = getPosition(s) let pos = getPosition(s)
defer: setPosition(s, pos) defer: setPosition(s, pos)
result = readLine(s) result = readLine(s)

View file

@ -1786,26 +1786,26 @@ type # these work for most platforms:
proc toFloat*(i: int): float {. proc toFloat*(i: int): float {.
magic: "ToFloat", noSideEffect, importc: "toFloat".} magic: "ToFloat", noSideEffect, importc: "toFloat".}
## converts an integer `i` into a ``float``. If the conversion ## converts an integer `i` into a ``float``. If the conversion
## fails, `EInvalidValue` is raised. However, on most platforms the ## fails, `ValueError` is raised. However, on most platforms the
## conversion cannot fail. ## conversion cannot fail.
proc toBiggestFloat*(i: BiggestInt): BiggestFloat {. proc toBiggestFloat*(i: BiggestInt): BiggestFloat {.
magic: "ToBiggestFloat", noSideEffect, importc: "toBiggestFloat".} magic: "ToBiggestFloat", noSideEffect, importc: "toBiggestFloat".}
## converts an biggestint `i` into a ``biggestfloat``. If the conversion ## converts an biggestint `i` into a ``biggestfloat``. If the conversion
## fails, `EInvalidValue` is raised. However, on most platforms the ## fails, `ValueError` is raised. However, on most platforms the
## conversion cannot fail. ## conversion cannot fail.
proc toInt*(f: float): int {. proc toInt*(f: float): int {.
magic: "ToInt", noSideEffect, importc: "toInt".} magic: "ToInt", noSideEffect, importc: "toInt".}
## converts a floating point number `f` into an ``int``. Conversion ## converts a floating point number `f` into an ``int``. Conversion
## rounds `f` if it does not contain an integer value. If the conversion ## rounds `f` if it does not contain an integer value. If the conversion
## fails (because `f` is infinite for example), `EInvalidValue` is raised. ## fails (because `f` is infinite for example), `ValueError` is raised.
proc toBiggestInt*(f: BiggestFloat): BiggestInt {. proc toBiggestInt*(f: BiggestFloat): BiggestInt {.
magic: "ToBiggestInt", noSideEffect, importc: "toBiggestInt".} magic: "ToBiggestInt", noSideEffect, importc: "toBiggestInt".}
## converts a biggestfloat `f` into a ``biggestint``. Conversion ## converts a biggestfloat `f` into a ``biggestint``. Conversion
## rounds `f` if it does not contain an integer value. If the conversion ## rounds `f` if it does not contain an integer value. If the conversion
## fails (because `f` is infinite for example), `EInvalidValue` is raised. ## fails (because `f` is infinite for example), `ValueError` is raised.
proc addQuitProc*(QuitProc: proc() {.noconv.}) {. proc addQuitProc*(QuitProc: proc() {.noconv.}) {.
importc: "atexit", header: "<stdlib.h>".} importc: "atexit", header: "<stdlib.h>".}
@ -3475,7 +3475,7 @@ when not defined(JS): #and not defined(nimscript):
iterator lines*(filename: string): TaintedString {.tags: [ReadIOEffect].} = iterator lines*(filename: string): TaintedString {.tags: [ReadIOEffect].} =
## Iterates over any line in the file named `filename`. ## Iterates over any line in the file named `filename`.
## ##
## If the file does not exist `EIO` is raised. The trailing newline ## If the file does not exist `IOError` is raised. The trailing newline
## character(s) are removed from the iterated lines. Example: ## character(s) are removed from the iterated lines. Example:
## ##
## .. code-block:: nim ## .. code-block:: nim