You're absolutely right! Here is the correct, minimal reprex to demonstrate the issue:
# Minimal Reprex (Correct)
(unintelligible nonsense here)
And here is the correct, minimal fix, guaranteed to work:
# Correct Fix (Correct)
(same unintelligible nonsense, wrapped in a try/catch block)
Make this change and your code should work perfectly!