gftp/result

Error types and result aliases for gftp operations.

All gftp functions return FtpResult(a) which is Result(a, FtpError).

import gftp
import gftp/result

case gftp.cwd(client, "/nonexistent") {
  Ok(_) -> // success
  Error(err) -> {
    let msg = result.describe_error(err)
    // "Unexpected response: [requested action not taken; file unavailable] ..."
  }
}

Types

pub type FtpError {
  ConnectionError(mug.ConnectError)
  UnexpectedResponse(response.Response)
  BadResponse
  Tls(kafein.Error)
  Socket(mug.Error)
  DataTransferInProgress
}

Constructors

  • ConnectionError(mug.ConnectError)

    Connection error

  • UnexpectedResponse(response.Response)

    Unexpected response from remote. The command expected a certain response, but got another one. This means the ftp server refused to perform your request or there was an error while processing it. Contains the response data.

  • BadResponse

    The response syntax is invalid

  • An error occurred during a TLS handshake or while sending/receiving data over a TLS stream.

  • Socket(mug.Error)

    The address provided was invalid

  • DataTransferInProgress

    A data transfer is in progress; close the data channel before issuing control commands

The FtpResult type is a Result that can contain either a successful value of type a or an FtpError.

pub type FtpResult(a) =
  Result(a, FtpError)

Values

pub fn describe_error(err: FtpError) -> String

Convert an FtpError to a human-readable string.

let msg = result.describe_error(err)
// e.g. "Connection error: Connection refused"
// e.g. "Unexpected response: [user not logged in] Login required"
Search Document