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) { ...@@ -245,10 +245,16 @@ func parseAnything(filename string) (*Metadata, error) {
type fileProvider struct{} 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) path = storage.Abs(path)
var m *Metadata
var err error
switch filetype { switch filetype {
case ".epub": case ".epub":
m, err = parseEpub(path) m, err = parseEpub(path)
...@@ -257,13 +263,10 @@ func (p *fileProvider) Lookup(storage *FileStorage, path, filetype string) (*Met ...@@ -257,13 +263,10 @@ func (p *fileProvider) Lookup(storage *FileStorage, path, filetype string) (*Met
case ".pdf": case ".pdf":
m, err = parseAnything(path) m, err = parseAnything(path)
default: default:
return nil, errors.New("unsupported file format") err = errors.New("unsupported file format")
}
if err != nil {
return nil, err
} }
return m, nil return
} }
func (p *fileProvider) GetBookCover(storage *FileStorage, path string) (string, error) { 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