Skip to content

Improve error message for non-numeric strands construction (#9218) - #9229

Open
LalitNarayanYadav wants to merge 2 commits into
processing:mainfrom
LalitNarayanYadav:fix/9218-strands-error-hint
Open

LalitNarayanYadav wants to merge 2 commits into
processing:mainfrom
LalitNarayanYadav:fix/9218-strands-error-hint

Conversation

@LalitNarayanYadav

@LalitNarayanYadav LalitNarayanYadav commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Addresses #9218

Changes

Improves the error thrown in mapPrimitiveDepsToIDs (src/strands/ir_builders.js) when a non-numeric value is passed into a scalar or vector construction.

Previously, the error stringified the raw value. In the case from #9218 (using filterColor directly instead of filterColor.texCoord), this dumped the internal hook callback's source code into the message.

Now the error:

  • Detects when the offending value is a function or object rather than a primitive
  • Describes it in plain terms (e.g. "a function") instead of stringifying it, which avoids the raw source dump
  • Adds a hint when the value looks like a strands hook or variable used directly, rather than a property on it

Before / after

Before (from #9218):

[p5.strands type error]: You've tried to construct a scalar or vector type with a non-numeric value: function(hookUserCallback) {
  const args = setupHook();
  hook._result = hookUserCallback(...args) ?? hook._result;
  finishHook();
}

After:

You've tried to construct a scalar or vector type with a non-numeric value: a function
This looks like a shader hook or strands variable used directly, rather than a property on it (e.g. you wrote `filterColor` instead of `filterColor.texCoord`).

Scope

This covers only the "better error content at the throw site" part of #9218. The following are left as follow-up work:

  • Filtering internal strandsNode frames out of the stack trace
  • Source mapping from transpiled code back to the original sketch lines

Tests

Adds a regression test in test/unit/webgl/p5.Shader.js that reproduces the filterColor * 30 mistake from the issue and asserts on the new message. The full p5.Shader suite passes (161/161).

PR Checklist

  • npm run lint passes
  • [Inline reference] is included / updated (N/A: no public API or docs changes)
  • [Unit tests] are included / updated

@LalitNarayanYadav
LalitNarayanYadav marked this pull request as ready for review September 30, 2026 18:09
@p5-bot

p5-bot Bot commented Sep 30, 2026

Copy link
Copy Markdown

Continuous Release

CDN link

Published Packages

Commit hash: b9e56b1

Previous deployments

This is an automated message.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant