Skip to content

fix: add friendly errors for hook lifecycle misuse - #9235

Merged
davepagurek merged 3 commits into
processing:mainfrom
bhabishnu:fix/strands-hook-lifecycle-errors
Oct 8, 2026
Merged

davepagurek merged 3 commits into
processing:mainfrom
bhabishnu:fix/strands-hook-lifecycle-errors

Conversation

@bhabishnu

@bhabishnu bhabishnu commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Resolves #9232

Changes:

  • Add a friendly scope error when set() is called outside a hook's begin() / end() block.
  • Add a friendly error when a value-returning hook reaches end() without a value.
  • Add a friendly error when begin() is called without a matching end().
  • Add regression tests for all three cases.

Testing:

  • npm test -- test/unit/webgl/p5.Shader.js — 164 passed
  • npm run lint — 0 errors (8 existing warnings)
  • git diff --check — clean

Screenshots of the change:
N/A

AI usage: Used ChatGPT for debugging and review. Claude Code generated the follow up implementation and regression test changes.

@welcome

welcome Bot commented Oct 2, 2026

Copy link
Copy Markdown

🎉 Thanks for opening this pull request! For guidance on contributing, check out our contributor guidelines and other resources for contributors!
🤔 Please ensure that your PR links to an issue, which has been approved for work by a maintainer; otherwise, there might already be someone working on it, or still ongoing discussion about implementation. You are welcome to join the discussion in an Issue if you're not sure!
🌸 Once your PR is merged, be sure to add yourself to the list of contributors on the readme page !

Thank You!

@p5-bot

p5-bot Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

@davepagurek davepagurek left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for making this, it's looking good! One suggestion: we know the name of the hook most of the time, right? Would we be able to make it say like (e.g.) "filterColor requires a value. Make sure to call filterColor.set(value) before filterColor.end()" to be more specific about what the user needs to write?

@bhabishnu

Copy link
Copy Markdown
Contributor Author

Thanks for the suggestion. I’ve updated all three lifecycle messages to include the hook name and added a finalColor regression test. All 164 tests in p5.Shader.js pass locally.

I also need to clarify the AI usage: Claude Code generated this follow up implementation and test changes, with ChatGPT assisting with review. I checked the AI Usage Policy afterward and see that this went beyond the assistive use it asks for. How would you prefer me to handle this revision?

@davepagurek

Copy link
Copy Markdown
Contributor

I also need to clarify the AI usage: Claude Code generated this follow up implementation and test changes, with ChatGPT assisting with review. I checked the AI Usage Policy afterward and see that this went beyond the assistive use it asks for. How would you prefer me to handle this revision?

Thanks for asking, I think being open about this and talking about it is always the right path if you're unsure!

We want to make sure that contributors are understanding the code that they're working with, so we think every line should be read and reviewed. Generally we want to make sure there's a human "at the wheel" so to speak, and that seems feasible with review of code for small PRs like this. For larger PRs that touch many things or make architectural changes, it's harder, so I'd personally encourage reviewing in small chunks so that you can still build a mental model for yourself of what is happening. Ultimately we just want to make sure there's always someone who understands each piece of the codebase.

In this instance it's small and easily reviewable so I think it's ok with disclosure like you've done!

@davepagurek davepagurek left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good now, thanks for the updates!

@davepagurek
davepagurek merged commit 93c7ddb into processing:main Oct 8, 2026
4 checks passed
@davepagurek

Copy link
Copy Markdown
Contributor

@all-contributors please add @bhabishnu for bug, code

@allcontributors

Copy link
Copy Markdown
Contributor

@davepagurek

I've put up a pull request to add @bhabishnu! 🎉

@bhabishnu

Copy link
Copy Markdown
Contributor Author

Thanks for reviewing and merging this! I appreciate you taking the time to explain the AI guidance too. I’ll make sure I understand and review every change I submit, and keep the AI assistance disclosed.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[p5.js 2.0+ Bug Report]: p5.strands hook lifecycle mistakes should give friendlier errors

2 participants