# frozen_string_literal: true module FFI module Libfuse module Adapter # 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 via #warn module Debug DEFAULT_FORMAT = "%
s % : The value of prefix option
def debug_callback(fuse_method, *args, **options)
debug(fuse_method, args, yield(*args), **options)
rescue SystemCallError => e
# expected behaviour
debug(fuse_method, args, "#{e.class.name}(errno=#{e.errno}): #{e.message}", **options)
raise
rescue StandardError, ScriptError => e
# unexpected, debug with backtrace
debug(fuse_method, args, (["#{e.class.name}: #{e.message}"] + e.backtrace).join("\n\t"), **options)
raise
end
# @!visibility private
def debug(fuse_method, args, result, **options)
warn debug_format(fuse_method, args, result, **options)
result
end
# @!visibility private
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
end
end
end
end