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:
parent
a3c581aa93
commit
9c5ed0dcca
3 changed files with 18 additions and 4 deletions
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue