Module: FFI::Libfuse::Adapter::Debug

Includes:
Safe
Included in:
Filesystem::PassThroughDir, Filesystem::VirtualFS
Defined in:
lib/ffi/libfuse/adapter/debug.rb

Overview

Note:

Debug includes Safe as it expects to handle (and re-raise) exceptions.

Debug callbacks

When included in a filesystem class, and if debugging is enabled via Main#fuse_debug, then installs a wrapper via #FuseCallbacks#fuse_wrappers to log callbacks.

Simple format options can be handled by ##debug_config, or override the Module Functions on an including class for more programmatic control of output.

Constant Summary collapse

DEFAULT_FORMAT =

Default format

See Also:

"%<p>s %<n>s %<t>s %<m>s(%<a>s)\n\t=> %<r>s"

Module Functions collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Safe

#default_errno, safe_callback

Class Method Details

.debug(fuse_method, args, result, **options) ⇒ Object

Logs the callback



87
88
89
# File 'lib/ffi/libfuse/adapter/debug.rb', line 87

def debug(fuse_method, args, result, **options)
  warn debug_format(fuse_method, args, result, **options)
end

.debug_callback(fuse_method, *args, **options) ⇒ Object

Debug fuse method, args and result of yielding args to the block

Parameters:

  • fuse_method (Symbol)

    the callback name

  • args (Array)

    callback arguments

  • options (Hash<Symbol,String>)

    see debug_format for defaults

Options Hash (**options):

Raises:

  • (SystemCallError)

    expected Errors raised from callbacks are logged with their cause (if any)

  • (StandardError, ScriptError)

    unexpected Errors raised from callbacks are logged with their backtrace



74
75
76
77
78
79
80
81
82
# File 'lib/ffi/libfuse/adapter/debug.rb', line 74

def debug_callback(fuse_method, *args, **options)
  result = yield(*args)
  debug(fuse_method, args, result, **options)
  result
rescue StandardError, ScriptError => e
  debug(fuse_method, args, error_message(e), **options)
  debug_error(e)
  raise
end

.debug_error(err) ⇒ Object

Log additional information for errors (cause/backtrace etc)



103
104
105
106
107
108
109
# File 'lib/ffi/libfuse/adapter/debug.rb', line 103

def debug_error(err)
  if err.is_a?(SystemCallError)
    warn "Caused by #{error_message(err.cause)}" if err.cause
  else
    warn err.backtrace.join("\n\t")
  end
end

.debug_format(fuse_method, args, result, prefix: 'DEBUG', strftime: '%FT%T%:z', format: DEFAULT_FORMAT) ⇒ String

Returns the formatted debug message.

Returns:

  • (String)

    the formatted debug message

See Also:



113
114
115
116
117
118
119
120
121
# File 'lib/ffi/libfuse/adapter/debug.rb', line 113

def debug_format(fuse_method, args, result, prefix: 'DEBUG', strftime: '%FT%T%:z', format: DEFAULT_FORMAT)
  format(format,
         p: prefix,
         n: Time.now.strftime(strftime),
         t: Thread.current.name || Thread.current,
         m: fuse_method,
         a: args.map(&:to_s).join(','),
         r: result)
end

.error_message(err) ⇒ String

Returns the detailed error message for err.

Parameters:

  • err (Exception)

Returns:

  • (String)

    the detailed error message for err



93
94
95
96
97
98
99
# File 'lib/ffi/libfuse/adapter/debug.rb', line 93

def error_message(err)
  if err.is_a?(SystemCallError)
    "#{err.class.name}(errno=#{err.errno}): #{err.message}"
  else
    "#{err.class.name}: #{err.message}"
  end
end

Instance Method Details

#debug?Boolean

Returns true if debug is enabled.

Returns:

  • (Boolean)

    true if debug is enabled



25
26
27
# File 'lib/ffi/libfuse/adapter/debug.rb', line 25

def debug?
  @debug
end

#debug_configHash<Symbol,String>

This method is abstract.

Configure debug output

Returns:



32
33
34
# File 'lib/ffi/libfuse/adapter/debug.rb', line 32

def debug_config
  {}
end