Re: Add pre-scan task?

Michael Herger <slim-b/[email protected]> Thu, 24 Mar 2022 15:41:38 +0100
Newsgroups gmane.music.equipment.slimdevices.devel
Message-ID <[email protected]>
> The createBackup function from the example above calls a function in
> plugin.pm that will read some values from the LMS databases (library and
> persistent) and write them to a file.

Be careful with loading Plugin.pm from the importer: the scanner doesn't 
support all the modules the server would. In particular if you're using 
any kind of networking you might be facing problems. I usually create a 
Common.pm or similar module with code which can be shared between server 
and scanner.

> Code:
> --------------------
>      eval { createBackup(); }
> --------------------
> 
> and if it returns an error, it wouldn't crash the scanner?

That's often one solution, yes. But I'd probably go lower level to only 
wrap the potentially blocking call, eg. reading/writing a file. Try to 
understand what might be failing, and whether you can't cover that 
failure in a more controlled way. eval can be a dangerous beast, 
potentially hiding easy problems like typos. At the very least do log $@ 
(which would have the eval's error).