Improve error handling to help prevent runtime errors

Adds input validation and safe property access to utility functions
to handle edge cases and invalid arguments gracefully
This commit is contained in:
Eddy G
2025-07-07 12:26:59 -04:00
parent a3c581aa93
commit 9c5ed0dcca
3 changed files with 18 additions and 4 deletions

View File

@@ -5,6 +5,11 @@ import { blob } from './fetch.mjs';
// a list of cached icons is used to avoid hitting the cache multiple times
const cachedImages = [];
const preloadImg = (src) => {
if (!src || typeof src !== 'string') {
console.warn(`preloadImg expects a URL string, received: '${src}' (${typeof src})`);
return false;
}
if (cachedImages.includes(src)) return false;
blob(src);
cachedImages.push(src);