feat(errorsx): cover more syscall errors and add tests (#430)
* feat(errorsx): cover more syscall errors and add tests Part of https://github.com/ooni/probe/issues/1505 * fix tests
This commit is contained in:
parent
3747598b4a
commit
14c1640f7f
7 changed files with 293 additions and 48 deletions
|
|
@ -1,5 +1,5 @@
|
|||
// Code generated by go generate; DO NOT EDIT.
|
||||
// Generated: 2021-07-02 15:15:17.997258 +0200 CEST m=+0.110031584
|
||||
// Generated: 2021-07-02 17:54:06.182341 +0200 CEST m=+0.120124584
|
||||
|
||||
package errorsx
|
||||
|
||||
|
|
@ -10,6 +10,42 @@ import (
|
|||
"syscall"
|
||||
)
|
||||
|
||||
// This enumeration lists the syscall-derived failures defined at
|
||||
// https://github.com/ooni/spec/blob/master/data-formats/df-007-errors.md
|
||||
//
|
||||
// See also the enumeration at failures.go for the failures that
|
||||
// DO NOT derive from system call errors.
|
||||
const (
|
||||
FailureOperationCanceled = "operation_canceled"
|
||||
FailureConnectionRefused = "connection_refused"
|
||||
FailureConnectionReset = "connection_reset"
|
||||
FailureHostUnreachable = "host_unreachable"
|
||||
FailureTimedOut = "timed_out"
|
||||
FailureAddressFamilyNotSupported = "address_family_not_supported"
|
||||
FailureAddressInUse = "address_in_use"
|
||||
FailureAddressNotAvailable = "address_not_available"
|
||||
FailureAlreadyConnected = "already_connected"
|
||||
FailureBadAddress = "bad_address"
|
||||
FailureBadFileDescriptor = "bad_file_descriptor"
|
||||
FailureConnectionAborted = "connection_aborted"
|
||||
FailureConnectionAlreadyInProgress = "connection_already_in_progress"
|
||||
FailureDestinationAddressRequired = "destination_address_required"
|
||||
FailureInterrupted = "interrupted"
|
||||
FailureInvalidArgument = "invalid_argument"
|
||||
FailureMessageSize = "message_size"
|
||||
FailureNetworkDown = "network_down"
|
||||
FailureNetworkReset = "network_reset"
|
||||
FailureNetworkUnreachable = "network_unreachable"
|
||||
FailureNoBufferSpace = "no_buffer_space"
|
||||
FailureNoProtocolOption = "no_protocol_option"
|
||||
FailureNotASocket = "not_a_socket"
|
||||
FailureNotConnected = "not_connected"
|
||||
FailureOperationWouldBlock = "operation_would_block"
|
||||
FailurePermissionDenied = "permission_denied"
|
||||
FailureProtocolNotSupported = "protocol_not_supported"
|
||||
FailureWrongProtocolType = "wrong_protocol_type"
|
||||
)
|
||||
|
||||
// toSyscallErr converts a syscall error to the
|
||||
// proper OONI error. Returns the OONI error string
|
||||
// on success, an empty string otherwise.
|
||||
|
|
@ -23,7 +59,7 @@ func toSyscallErr(err error) string {
|
|||
}
|
||||
switch errno {
|
||||
case ECANCELED:
|
||||
return FailureInterrupted
|
||||
return FailureOperationCanceled
|
||||
case ECONNREFUSED:
|
||||
return FailureConnectionRefused
|
||||
case ECONNRESET:
|
||||
|
|
@ -31,7 +67,53 @@ func toSyscallErr(err error) string {
|
|||
case EHOSTUNREACH:
|
||||
return FailureHostUnreachable
|
||||
case ETIMEDOUT:
|
||||
return FailureGenericTimeoutError
|
||||
return FailureTimedOut
|
||||
case EAFNOSUPPORT:
|
||||
return FailureAddressFamilyNotSupported
|
||||
case EADDRINUSE:
|
||||
return FailureAddressInUse
|
||||
case EADDRNOTAVAIL:
|
||||
return FailureAddressNotAvailable
|
||||
case EISCONN:
|
||||
return FailureAlreadyConnected
|
||||
case EFAULT:
|
||||
return FailureBadAddress
|
||||
case EBADF:
|
||||
return FailureBadFileDescriptor
|
||||
case ECONNABORTED:
|
||||
return FailureConnectionAborted
|
||||
case EALREADY:
|
||||
return FailureConnectionAlreadyInProgress
|
||||
case EDESTADDRREQ:
|
||||
return FailureDestinationAddressRequired
|
||||
case EINTR:
|
||||
return FailureInterrupted
|
||||
case EINVAL:
|
||||
return FailureInvalidArgument
|
||||
case EMSGSIZE:
|
||||
return FailureMessageSize
|
||||
case ENETDOWN:
|
||||
return FailureNetworkDown
|
||||
case ENETRESET:
|
||||
return FailureNetworkReset
|
||||
case ENETUNREACH:
|
||||
return FailureNetworkUnreachable
|
||||
case ENOBUFS:
|
||||
return FailureNoBufferSpace
|
||||
case ENOPROTOOPT:
|
||||
return FailureNoProtocolOption
|
||||
case ENOTSOCK:
|
||||
return FailureNotASocket
|
||||
case ENOTCONN:
|
||||
return FailureNotConnected
|
||||
case EWOULDBLOCK:
|
||||
return FailureOperationWouldBlock
|
||||
case EACCES:
|
||||
return FailurePermissionDenied
|
||||
case EPROTONOSUPPORT:
|
||||
return FailureProtocolNotSupported
|
||||
case EPROTOTYPE:
|
||||
return FailureWrongProtocolType
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue