Exception: KerberosAuthenticator::Krb5::LibCallError

Inherits:
Error show all
Defined in:
lib/kerberos_authenticator/krb5/error.rb

Overview

A Kerberos error returned from a library call as a ‘krb5_error_code`.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context_ptr, krb5_error_code) ⇒ LibCallError

Initializes a new LibCallError using an error code and the relevant Context to provide a friendly error message.

Parameters:

  • context_ptr (FFI::Pointer)

    A Context’s pointer

  • krb5_error_code (Integer)

    An integer used to convey a operation’s status

See Also:



24
25
26
27
28
29
# File 'lib/kerberos_authenticator/krb5/error.rb', line 24

def initialize(context_ptr, krb5_error_code)
  @error_code = krb5_error_code
  error_message, error_ptr = Krb5.get_error_message(context_ptr, krb5_error_code)
  self.class.release(error_ptr)
  super String.new(error_message).force_encoding('UTF-8')
end

Instance Attribute Details

#error_codeInteger (readonly)

Returns the krb5_error_code used to convey the status of a Kerberos library operation.

Returns:

  • (Integer)

    the krb5_error_code used to convey the status of a Kerberos library operation.

See Also:



# File 'lib/kerberos_authenticator/krb5/error.rb', line 12

Class Method Details

.raise_if_error(context_ptr = nil) { ... } ⇒ Integer

Used to wrap Kerberos library functions that return a krb5_error_code.

Yields:

  • A call to a Kerberos library function

Yield Returns:

  • (Integer)

    a krb5_error_code

Returns:

  • (Integer)

    always returns zero on success

Raises:

  • (LibCallError)

    if the krb5_error_code differed from zero



43
44
45
46
47
# File 'lib/kerberos_authenticator/krb5/error.rb', line 43

def self.raise_if_error(context_ptr = nil)
  err = yield
  return 0 if err.zero?
  raise self.new(context_ptr, err)
end

.release(pointer) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Frees an error message



34
35
36
# File 'lib/kerberos_authenticator/krb5/error.rb', line 34

def self.release(pointer)
  Krb5.free_error_message(Context.context.ptr, pointer)
end