-- 'Either' with three choices. A "Info" return value means that
-- the XML document *was* processed, so it should be removed.
--
-data ImportResult = Err String | Info String | Succ Int
+data ImportResult =
+ ImportFailed String -- ^ Failure with an error message.
+ | ImportSkipped String -- ^ We processed the file, but didn't import it.
+ -- The reason is contained in the second field.
+ | ImportSucceeded Int -- ^ We did import records, and here's how many.
+ | ImportUnsupported String -- ^ We didn't know how to process this file.
+ -- The second field should contain info.
-- | Instances of this type know how to insert themselves into a
-- Groundhog database.
runMigration defaultMigrationLogger $ migrate dummy
let root_element = unpickleDoc xpickle xml
case root_element of
- Nothing -> return $ Err "Could not unpickle document in import_generic."
+ Nothing -> return $
+ ImportFailed "Could not unpickle document in import_generic."
Just elt -> do
ids <- mapM insert (g elt)
- return $ Succ (length ids)
+ return $ ImportSucceeded (length ids)