From ad84ef19d82ed696466bd33e4cb49d506ffa353b Mon Sep 17 00:00:00 2001 From: MASTERsj01 Date: Sun, 8 Mar 2026 19:18:08 +0530 Subject: [PATCH] fix: replace raw console.log calls with p5._friendlyError across multiple modules MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace raw console.log() calls with p5._friendlyError() so that warning messages respect p5.disableFriendlyErrors and can be translated via the i18n system. Changes: - src/data/local_storage.js: 5 console.log → p5._friendlyError (storeItem, getItem, removeItem validation warnings) - src/dom/p5.MediaElement.js: remove leftover debug console.log(id) in removeCue() - src/image/p5.Image.js: 1 console.log → p5._friendlyError (setFrame invalid frame index warning) - src/events/pointer.js: 1 console.log → p5._friendlyError (requestPointerLock browser capability warning) - src/dom/dom.js: 1 console.log → p5._friendlyError (createFileInput File APIs browser capability warning) Addresses #8608, #8609, #8610, #8611 --- src/data/local_storage.js | 22 +++++++++++++--------- src/dom/dom.js | 5 +++-- src/dom/p5.MediaElement.js | 1 - src/events/pointer.js | 2 +- src/image/p5.Image.js | 5 +++-- 5 files changed, 20 insertions(+), 15 deletions(-) diff --git a/src/data/local_storage.js b/src/data/local_storage.js index c688e7dc9e..f625618c95 100644 --- a/src/data/local_storage.js +++ b/src/data/local_storage.js @@ -114,18 +114,20 @@ function storage(p5, fn){ */ fn.storeItem = function(key, value) { if (typeof key !== 'string') { - console.log( - `The argument that you passed to storeItem() - ${key} is not a string.` + p5._friendlyError( + `The argument that you passed to storeItem() - ${key} is not a string.`, + 'storeItem' ); } if (key.endsWith('p5TypeID')) { - console.log( - `The argument that you passed to storeItem() - ${key} must not end with 'p5TypeID'.` + p5._friendlyError( + `The argument that you passed to storeItem() - ${key} must not end with 'p5TypeID'.`, + 'storeItem' ); } if (typeof value === 'undefined') { - console.log('You cannot store undefined variables using storeItem().'); + p5._friendlyError('You cannot store undefined variables using storeItem().', 'storeItem'); } let type = typeof value; switch (type) { @@ -263,8 +265,9 @@ function storage(p5, fn){ let value = localStorage.getItem(key); const type = localStorage.getItem(`${key}p5TypeID`); if (typeof type === 'undefined') { - console.log( - `Unable to determine type of item stored under ${key}in local storage. Did you save the item with something other than setItem()?` + p5._friendlyError( + `Unable to determine type of item stored under ${key}in local storage. Did you save the item with something other than setItem()?`, + 'getItem' ); } else if (value !== null) { switch (type) { @@ -418,8 +421,9 @@ function storage(p5, fn){ */ fn.removeItem = function(key) { if (typeof key !== 'string') { - console.log( - `The argument that you passed to removeItem() - ${key} is not a string.` + p5._friendlyError( + `The argument that you passed to removeItem() - ${key} is not a string.`, + 'removeItem' ); } localStorage.removeItem(key); diff --git a/src/dom/dom.js b/src/dom/dom.js index 1b816b4e91..7fb1fe1334 100644 --- a/src/dom/dom.js +++ b/src/dom/dom.js @@ -1832,8 +1832,9 @@ function dom(p5, fn){ // If File API's are not supported, throw Error if (!(window.File && window.FileReader && window.FileList && window.Blob)) { - console.log( - 'The File APIs are not fully supported in this browser. Cannot create element.' + p5._friendlyError( + 'The File APIs are not fully supported in this browser. Cannot create element.', + 'createFileInput' ); return; } diff --git a/src/dom/p5.MediaElement.js b/src/dom/p5.MediaElement.js index 815b83fbf7..9a9890d8ff 100644 --- a/src/dom/p5.MediaElement.js +++ b/src/dom/p5.MediaElement.js @@ -1170,7 +1170,6 @@ class MediaElement extends Element { removeCue(id) { for (let i = 0; i < this._cues.length; i++) { if (this._cues[i].id === id) { - console.log(id); this._cues.splice(i, 1); } } diff --git a/src/events/pointer.js b/src/events/pointer.js index 4a8226c43a..b14b7c25d4 100644 --- a/src/events/pointer.js +++ b/src/events/pointer.js @@ -1861,7 +1861,7 @@ function pointer(p5, fn, lifecycles){ canvas.requestPointerLock = canvas.requestPointerLock || canvas.mozRequestPointerLock; if (!canvas.requestPointerLock) { - console.log('requestPointerLock is not implemented in this browser'); + p5._friendlyError('requestPointerLock is not implemented in this browser', 'requestPointerLock'); return false; } canvas.requestPointerLock(); diff --git a/src/image/p5.Image.js b/src/image/p5.Image.js index 2d5e8070ba..80e5781524 100644 --- a/src/image/p5.Image.js +++ b/src/image/p5.Image.js @@ -1605,8 +1605,9 @@ class Image { props.displayIndex = index; this.drawingContext.putImageData(props.frames[index].image, 0, 0); } else { - console.log( - 'Cannot set GIF to a frame number that is higher than total number of frames or below zero.' + p5._friendlyError( + 'Cannot set GIF to a frame number that is higher than total number of frames or below zero.', + 'setFrame' ); } }