Skip to content

Commit 5e5240c

Browse files
committed
Gracefully handle missing user id
1 parent 1f39762 commit 5e5240c

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

lib/chef/knife/ec_key_import.rb

+7-1
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,16 @@ def insert_key_data_for_user(d)
129129
end
130130
ui.msg "Updating key data for user[#{d['name']}]"
131131
new_id = if config[:skip_ids]
132-
db[:users].where(:username => d['name']).first[:id]
132+
db[:users].where(:username => d['name']).first&.[](:id)
133133
else
134134
d['id']
135135
end
136+
137+
if new_id.nil?
138+
Chef::Log.debug("Unable to find user id for #{d['name']}")
139+
return
140+
end
141+
136142
Chef::Log.debug("Found user id for #{d['name']}: #{new_id}")
137143
upsert_key_record(key_record_for_db(d, new_id))
138144
end

0 commit comments

Comments
 (0)