[p5.js 2.0+ Bug Report]: storeItem() validation branches are missing `return`, so bad input throws a TypeError or is stored anyway
Los mantenedores suelen responder en 3 días
Evaluación
- Dificultad
- 1/5
- Tiempo estimado
- Menos de una hora
- Aptitud para principiantes
- 85/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- javascript
- Área
- data
Línea de trabajo
Comienza en src/data/local_storage.js: storeItem() alrededor de la línea 114 y removeItem() alrededor de la línea 424, donde las tres ramas de validación informan a través de p5._friendlyError y luego continúan. Reproduce con el snippet del issue: storeItem(42, 'hello') debería informar y detenerse en lugar de lanzar TypeError: key.endsWith is not a function, y storeItem('k', undefined) debería dejar getItem('k') vacío en lugar de devolver la cadena "undefined". Hecho significa que cada rama retorna antes de cualquier llamada a localStorage, con tests que cubran ambos casos; el try/catch propuesto alrededor de las dos llamadas a setItem es un seguimiento separable.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Most appropriate sub-area of p5.js?
- Data
p5.js version
2.3.2 (verified on main @ 94fb07d)
Web browser and version
All
Operating system
All
Steps to reproduce this
Steps:
- Run the sketch below.
storeItem(42, 'hello')prints the friendly error about the key not being a string, then throwsTypeError: key.endsWith is not a functionand halts the sketch.- Comment that line out.
storeItem('k', undefined)prints "You cannot store undefined variables using storeItem()" — and then stores it anyway. getItem('k')returns the string"undefined".
Snippet:
function setup() {
storeItem(42, 'hello'); // friendly error, then an uncaught TypeError
storeItem('k', undefined); // "You cannot store undefined variables..."
print(getItem('k')); // "undefined"
print(typeof getItem('k')); // "string"
}
Cause
None of the three validation branches in storeItem() returns after reporting the error, so execution falls through into code that assumed the input was already valid:
// src/data/local_storage.js:114
fn.storeItem = function (key, value) {
if (typeof key !== 'string') {
p5._friendlyError(
`The argument that you passed to storeItem() - ${key} is not a string.`,
'storeItem'
);
} // <- no return
if (key.endsWith('p5TypeID')) { // <- throws when key is a number
p5._friendlyError(...);
} // <- no return
if (typeof value === 'undefined') {
p5._friendlyError(
'You cannot store undefined variables using storeItem().',
'storeItem'
);
} // <- no return
let type = typeof value;
switch (type) { /* ... 'undefined' hits `default`, unchanged ... */ }
localStorage.setItem(key, value); // stores "undefined"
localStorage.setItem(`${key}p5TypeID`, type); // stores type "undefined"
};
So the non-string-key case produces a friendly error immediately followed by a hard TypeError from the next check, and the undefined-value case produces a message that is simply not true about what happened — the value is written to localStorage, tagged with type "undefined", and handed back by getItem() as a string.
fn.removeItem (src/data/local_storage.js:424) has the same shape: it reports a non-string key and then calls localStorage.removeItem(key) regardless.
Expected behaviour
Reporting an invalid argument should stop the operation. Nothing should be written, nothing downstream should see input it cannot handle, and the message should describe what actually happened.
Suggested fix
Add return; to each validation branch in storeItem() and removeItem():
if (typeof key !== 'string') {
p5._friendlyError(
`The argument that you passed to storeItem() - ${key} is not a string.`,
'storeItem'
);
+ return;
}
…and likewise for the p5TypeID suffix check and the undefined value check.
One related thing, if you want it in the same PR
The two localStorage.setItem calls are unguarded. They throw QuotaExceededError when storage is full and SecurityError where site data is blocked (Safari private browsing, or a sketch embedded in a third-party iframe with cookies restricted) — both of which surface as uncaught exceptions that stop the sketch rather than as friendly errors.
There is also a consistency hazard: if the first setItem succeeds and the second one fails, the value is stored without its p5TypeID tag, and getItem() then returns it as an untyped raw string. Wrapping both calls in a single try/catch that reports through p5._friendlyError would make that legible and keep the pair atomic. Happy to split this out into its own issue if you'd rather keep them separate.
I'd be glad to open a PR for the missing returns with tests for both cases.
- Lenguaje dominante
- JavaScript
- Estrellas
- 24.1k
- Forks
- 3.9k
- Merge medio
- 2 d 20 h
- PR fusionados (30 d)
- 37
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de processing/p5.js
-
[p5.js 2.0+ Bug Report]: touches[0].x lags one pointer event behind while draggingPosiblemente ocupada @titanstride la tomó hace 1 día. AbiertoArea:Events p5.js 2.0+
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
processing/p5.js#9305 · 1 comentario ·
Los mantenedores suelen responder en 3 días
-
loadModel() options break without fileType and ignore flipU/flipVPosiblemente ocupada @saniyaa-17 la tomó hace 1 día. AbiertoArea:WebGL p5.js 2.0+
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
processing/p5.js#9302 · 2 comentarios ·
Los mantenedores suelen responder en 3 días
-
[p5.js 2.0+ Bug Report]: key docs needs updatingPosiblemente ocupada @MannXo la tomó hace 1 día. AbiertoHelp Wanted
Dificultad 1/5 Menos de una hora Aptitud para principiantes 62/100
processing/p5.js#9296 · 5 comentarios · 1 reacción ·
Los mantenedores suelen responder en 3 días
-
False positive FES warning for loadModel(path, callback)Posiblemente ocupada @xsupremeyx la tomó hace 2 días. Abiertop5.js 2.0+
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
processing/p5.js#9295 · 1 comentario · 1 asignado ·
Los mantenedores suelen responder en 3 días
-
Add unit tests for noiseDetail()Posiblemente ocupada @harshiltewari2004 la tomó hace 4 días. AbiertoArea:Math Enhancement
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
processing/p5.js#9253 · 2 comentarios · 1 asignado ·
Los mantenedores suelen responder en 3 días
Todos los issues de processing/p5.js
Issues similares
-
area:plugins enhancement platform:vscode
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
anthropics/claude-code#103166 ·
Los mantenedores suelen responder en 1 día
-
Add: Kids Zone LogoAbiertocheck:failed logos:add
Dificultad 1/5 Menos de una hora Aptitud para principiantes 78/100
-
[workshop-sim] Improve: Add verifiable checkpoint and bridge to Step 5 (What Are Agentic Workflows?)Abiertofeedback simulation workshop
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
githubnext/gh-aw-workshop#4715 ·
Los mantenedores suelen responder en 1 día
-
getComputedStyle ignores a rule whose selector list contains a pseudo-element (regression in 30.x)Posiblemente ocupada @chiragjangiir la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 80/100
Los mantenedores suelen responder en 1 día
-
external-plugin external-plugin-canvas needs-review:MEDIUM ready-for-review
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
github/awesome-copilot#5153 · 2 comentarios ·
Los mantenedores suelen responder en 1 día