p5.strands transpilation error gives no context about the callback
Los mantenedores suelen responder en 2 días
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 68/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- javascript
- Área
- computer-graphics, web-dev
Línea de trabajo
Empieza por la llamada a parse() en src/strands/strands_transpiler.js dentro de transpileStrandsToJS(); después, lee cómo se gestionan los errores de strands y compara en el issue los ejemplos de funciones enlazadas y de código fuente no válido. Haz que los errores de análisis produzcan un error útil de p5.strands que identifique el problema del callback y su posición cuando esté disponible, y gestiona directamente el código fuente inutilizable de las funciones enlazadas. El trabajo estará listo cuando ambos ejemplos produzcan un error legible y las rutas de #9310 sigan sin cambios.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Most appropriate sub-area of p5.js?
- Accessibility
- Color
- Core/Environment/Rendering
- Data
- DOM
- Events
- Image
- IO
- Math
- Typography
- Utilities
- WebGL
- WebGPU
- p5.strands
- Build process
- Unit testing
- Internationalization
- Friendly errors
- Other (specify if possible)
p5.js version
2.4.0-rc.1
Web browser and version
Chromium 153.0.8010.12, running p5.js 2.4.0-rc.1 from cdn.jsdelivr.net, which is the same build the p5.js Web Editor loads
Operating system
macOS
Steps to reproduce this
Steps:
- Open the p5.js Web Editor and start a new sketch.
- Paste the snippet below as-is. It is a complete sketch, nothing else is needed.
- Run the sketch and open the browser console.
Snippet:
function setup() {
createCanvas(200, 200, WEBGL);
const fn = () => {};
buildMaterialShader(fn.bind(null));
}
Console output
🌸 p5.js says: p5.strands shaders are experimental, so functions for building shaders and the hooks available within them may change in future versions. You can get involved by giving feedback to help direct its development! For more info, see https://p5js.org/contribute/p5.strands/
Uncaught (in promise) SyntaxError: Unexpected token (1:23)
Captured in Chromium 153 against the same [email protected] build the Web Editor loads, from a local page. Running it in the Web Editor gives the same two lines.
What I expected
One legible error that names the problem in my callback and points at it, the way the rest of the friendly error system does.
What actually happened
A raw acorn SyntaxError with no mention of p5.strands and no pointer to the callback. The stack the browser shows is ten frames of acorn internals, so it does not even show which p5 function was involved. Setting Error.stackTraceLimit = 100 shows the rest of the chain:
at parse (p5.js:82651)
at transpileStrandsToJS (p5.js:114210)
at p5.Shader.modify (p5.js:116671)
at fn.buildMaterialShader (p5.js:58459)
The line numbers above are from the published 2.4.0-rc.1 bundle. In the source tree this is the parse() call inside transpileStrandsToJS(), in src/strands/strands_transpiler.js (around line 2116).
The cause is that p5.strands rebuilds the callback from its source text, and the source of a bound function is function () { [native code] }, which is not valid JavaScript. The failure happens inside acorn's parse(), before buildStrandsCallback() is reached, so none of the strands error handling runs and the user is left with an acorn error that mentions neither p5.strands nor their callback.
A callback source that is not valid JavaScript fails the same way:
function setup() {
createCanvas(200, 200, WEBGL);
buildMaterialShader('void main(){}');
}
Uncaught (in promise) SyntaxError: Unexpected token (1:12)
Possible approach
- Wrap the
parse()call intranspileStrandsToJS()so a syntax error in the callback source becomes a strands friendly error instead of escaping as a raw acornSyntaxError. The message should say that the callback source could not be parsed, and show the offending position, e.g.Unexpected token (1:23). - Detect the case where the callback source is not usable at all, such as a bound function, whose
toString()isfunction () { [native code] }, and say that directly, since no amount of position information helps there. - Leave the two paths in #9310 unchanged, so this can be a separate change.
Happy to fix this myself once an approach is agreed on.
Related issues
- #9252 is the same shape of problem from a different trigger. There, an unsupported operator crashes inside the transpiler and the error points at p5.js internals. Here, the callback source cannot be parsed at all, and the error is a raw acorn
SyntaxError. - #9218 is about a runtime error inside a strands callback whose message stringifies internal state. The open PR for it, #9229, targets a different throw site in
src/strands/ir_builders.js, and it leaves stack-trace filtering and source mapping as follow-ups. What I am reporting here happens earlier, during transpilation, and never reaches the strands error handling at all. - #9310 covers the two paths that dump the parsed program, or the parameter names and body, to the console before throwing. It was confirmed on 2.4.0-rc.1 and closed. This issue is about the path that was not covered, where the user gets no legible response at all.
I did not want to reopen #9310 for this, since it looks like a separate failure mode, but happy to fold it in if that is easier.
Scope
This one is entirely inside p5.strands, in src/strands/strands_transpiler.js. I am happy to work on it, and happy to pair with @subhranshudash13-dotcom, who offered to pick up the strands side of #9310. I can also see @LalitNarayanYadav working on #9218 and @harshiltewari2004 on #9252, so I would rather not step on either of you, happy to coordinate.
There is a related problem in the friendly error system's parameter validator, where the message comes out empty and the raw Zod error object is logged for callback parameters. That one is outside p5.strands, and it may already be covered by #9209, so I will look into it separately rather than file it right away.
- Lenguaje dominante
- JavaScript
- Estrellas
- 24.2k
- Forks
- 3.9k
- Merge medio
- 2 d 17 h
- PR fusionados (30 d)
- 36
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
-
Area:Core p5.js 2.0+
Dificultad 2/5 1-3 horas Aptitud para principiantes 66/100
processing/p5.js#9319 · 1 comentario ·
Los mantenedores suelen responder en 2 días
-
Area:DOM Good First Issue p5.js 2.0+
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
processing/p5.js#9316 · 4 comentarios · 1 reacción ·
Los mantenedores suelen responder en 2 días
-
[p5.js 2.0+ Bug Report]: touches[0].x lags one pointer event behind while draggingQuizá libre de nuevo @titanstride la tomó hace 9 días y no hay ningún pull request abierto. 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 2 días
-
loadModel() options break without fileType and ignore flipU/flipVQuizá libre de nuevo @saniyaa-17 la tomó hace 9 días y no hay ningún pull request abierto. 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 2 días
-
[p5.js 2.0+ Bug Report]: key docs needs updatingQuizá libre de nuevo @MannXo la tomó hace 9 días y no hay ningún pull request abierto. AbiertoHelp Wanted
Dificultad 1/5 Menos de una hora Aptitud para principiantes 62/100
processing/p5.js#9296 · 6 comentarios · 1 reacción ·
Los mantenedores suelen responder en 2 días
Todos los issues de processing/p5.js
Issues similares
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
type/bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
flarum/framework#5301 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
AOSSIE-Org/BabyNest#284 ·
Los mantenedores suelen responder en 1 día
-
status:untriaged
Dificultad 1/5 Menos de una hora Aptitud para principiantes 86/100
midnightntwrk/servicedesk#275 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 85/100
seek4science/seek#2762 ·
Los mantenedores suelen responder en 5 días