Commit 449c44bc authored by ale's avatar ale

recover from panic in metadata extraction

parent 37aff84a
......@@ -245,10 +245,16 @@ func parseAnything(filename string) (*Metadata, error) {
type fileProvider struct{}
func (p *fileProvider) Lookup(storage *FileStorage, path, filetype string) (*Metadata, error) {
func (p *fileProvider) Lookup(storage *FileStorage, path, filetype string) (m *Metadata, err error) {
// Catch panics from some of the underlying libraries (gmobi
// in particular) and transform them into errors.
defer func() {
if r := recover(); r != nil {
err = fmt.Errorf("panic(): %v", r.(error))
}
}()
path = storage.Abs(path)
var m *Metadata
var err error
switch filetype {
case ".epub":
m, err = parseEpub(path)
......@@ -257,13 +263,10 @@ func (p *fileProvider) Lookup(storage *FileStorage, path, filetype string) (*Met
case ".pdf":
m, err = parseAnything(path)
default:
return nil, errors.New("unsupported file format")
}
if err != nil {
return nil, err
err = errors.New("unsupported file format")
}
return m, nil
return
}
func (p *fileProvider) GetBookCover(storage *FileStorage, path string) (string, error) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment