# HG changeset patch # User Matthew Wild # Date 1408908844 -3600 # Node ID 45843df81db0937027e882b0fa4e2d474415338c # Parent f1166645a56c1dff4c7709097ab82f792e1714c1 sendfilecontent: Fix indentation and show error if file cannot be opened diff -r f1166645a56c -r 45843df81db0 clix/sendfilecontent.lua --- a/clix/sendfilecontent.lua Wed Aug 20 12:05:46 2014 +0200 +++ b/clix/sendfilecontent.lua Sun Aug 24 20:34:04 2014 +0100 @@ -3,6 +3,7 @@ print("Send file content"); return; end + local function on_connect(conn) local function send_message(text) conn:send(verse.message({ to = opts.to, @@ -10,16 +11,20 @@ :body(text)); end if opts.file then - local f = io.open(opts.file, "rb") - local content = f:read("*all") - f:close() - if content:len() < 2000 then - send_message(content); - else - conn:error("File size too large. Cannot send file"); - end - conn:close(); + local f, err = io.open(opts.file, "rb") + if not f then + conn:error("Unable to open file: %s", err); + else + local content = f:read("*all") + f:close() + if content:len() < 2000 then + send_message(content); + else + conn:error("File size too large. Cannot send file"); + end + end end + conn:close(); end clix_connect(opts, on_connect); end