@theducks & @Manichean: Any chance you have books in your library that have no formats? Kovid found a bug in get_metadata last night that explains Manichean's exception. I don't know about theducks' case, because the exception text is missing.
@Manichean: exceptions during set_books_in_library will cause no end of troubles. Lets wait to trace down the second issue (add_book exception), because it will probably go away. I too use folder devices for lots of testing, for exactly the same reason. However, I can't test collections that way.
@theducks: how big is your library and on your device? Assuming the problem is missing formats, then 55 seconds in set_books_in_library is a bit excessive.