If I understand you correctly, you expect error from
if `cryptsetup luksOpen --key-file /home/adam/klucz.bin #{cryptdevice} crypt-tmp`
line. Then the begin-rescue-end
block should work:
Facter.add(:docexists) do
setcode do
begin
cryptdevice = File.read("/home/adam/.cryptdevice")
if `cryptsetup luksOpen --key-file /home/adam/klucz.bin #{cryptdevice} crypt-tmp`
tmp = `cryptsetup luksClose crypt-tmp`
true
else
false
end
rescue => e
# handle error
end
end
end