Be more robust about i/o failures to the keychain.
authorRyan C. Gordon <icculus@icculus.org>
Tue, 31 Mar 2015 20:18:10 -0400
changeset 44 2150bce729df
parent 43 85b1cb11d948
child 45 cf6a06f368e6
child 51 30d2d7598591
Be more robust about i/o failures to the keychain.

(and bail immediately if it's clearly missing.)
1pass.lua
--- a/1pass.lua	Sat Mar 28 22:33:10 2015 -0400
+++ b/1pass.lua	Tue Mar 31 20:18:10 2015 -0400
@@ -315,6 +315,9 @@
 local function prepItems()
     items = {}
     local contents = loadContents()
+    if contents == nil then
+        return false
+    end
     for i,v in ipairs(contents) do
         local t = v[2]
         if items[t] == nil then
@@ -323,6 +326,7 @@
         local bucket = items[t]
         bucket[#bucket+1] = { uuid=v[1], type=t, name=v[3], url=v[4] }  -- !!! FIXME: there are more fields, don't know what they mean yet.
     end
+    return true
 end
 
 local passwordUnlockTime = nil
@@ -378,7 +382,10 @@
         end
     end
 
-    prepItems()
+    if not prepItems() then
+        keyhookRunning = false
+        return
+    end
 
     local topmenu = makeGuiMenu()
     local favesmenu = makeGuiMenu()
@@ -446,6 +453,16 @@
 --end
 
 -- !!! FIXME: message box, exit if basedir is wack.
+local f = io.open(basedir .. "/contents.js", "rb")
+if f == nil then
+    print("ERROR: Couldn't read your 1Password keychain in '" .. basedir .. "'.")
+    print("ERROR: Please make sure it exists and you have permission to access it.")
+    print("ERROR: (maybe you need to run 'ln -s ~/Dropbox/1Password' here?")
+    print("ERROR: Giving up for now.")
+    os.exit(1)
+end
+f:close()
+
 -- !!! FIXME: this can probably happen in C now (the Lua mainline is basically gone now).
 setPowermateLED(false)  -- off by default
 print("Now waiting for the magic key combo (probably Alt-Meta-\\) ...")