Database updates are not immediately processed, but added to the so-called PUL (pending update list) [1] and executed at the very end of the query. When the updates are executed. This means that try/catch won’t have any effect, as the mere addition of the operation
to the PUL does not raise any errors.
The interesting question is why the error is raised at all. Do you have multiple independent instances of BaseX that access the same databases? If not, can you imagine an example that allows us to reproduce the behavior?
Von: Lizzi, Vincent via BaseX-Talk <basex-talk@mailman.uni-konstanz.de>
Gesendet: Donnerstag, September 25, 2025 9:15:45 PM
An: Christian Grün via BaseX-Talk <basex-talk@mailman.uni-konstanz.de>
Betreff: [basex-talk] db:drop error not being caught
Hi all,
I have a query that is intended to delete outdated databases. This has been working but I recently found that if a database is locked the process stops with an error such as:
[db:lock] Database 'name' cannot be updated, it is opened by another process.
As a result, the process is stopped by any database being in a locked state. I would have thought that the try / catch around db:drop would catch the error and allow the process to skip over any locked databases.
declare variable $age external := 'PT1M'; (: age 1 minute for testing :)
let $cutoff := current-dateTime() - xs:dayTimeDuration($age)
let $databases := db:list-details()[xs:dateTime(@modified-date) lt $cutoff]
return (
admin:write-log('cleanup delete items older than ' || $cutoff),
for $db in $databases return (
admin:write-log('cleanup deleting database ' || $db),
try {
db:drop($db)
} catch * {
admin:write-log('cleanup error deleting ' || $db || ': ' || $err:description, 'ERROR')
}
)
)
I tried replacing catch * with catch db:open to catch the specific error, but that hasn't helped.
Why is the error not caught, and is there a better way to write this query to avoid this problem?
Thanks,
Vincent
______________________________________________
Vincent M. Lizzi
Head of Information Standards | Taylor & Francis Group
E-Mail: vincent.lizzi@taylorandfrancis.com
Web: www.tandfonline.com
Time zone: US Eastern
Taylor & Francis is a trading name of Informa UK Limited,
registered in England under no. 1072954
"Everything should be made as simple as possible, but not simpler."