Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-add improved error messages with fixes #784

Merged
merged 3 commits into from
Aug 19, 2024

Conversation

jeremy46231
Copy link
Contributor

This PR is a fixed version of the original PR (#717). It caused errors in projects that people had already made. This version has been tested on every project in the gallery, as well as every open PR, and every issue has been solved.

  • There were some subtle logic bugs in my implementation of assertions, they have been fixed.
  • 9 gallery projects had problems that did not prevent them from running before, but rightly trigger errors now. All of those projects have been fixed as unobtrusively as possible.
  • 3 open PRs had similar problems. I contacted the authors on Slack and left reviews on their PRs explaining what was wrong and exactly how to fix it (so they could press a button and accept my fixes).

Summary of the affected projects

Gallery projects

  • GSLV.Mk.III by Samrat - removed an extra wrapper array
  • Gallifreyan by Shav Kinderlehrer - removed empty placeholder arrays
  • tennis racket by ahowden27 - removed extra wrapper arrays
  • UnionedPolygons by sosenteam - converted multiple arguments into array
  • cloudyFibonacci by Yohance - corrected array access syntax
  • Blot Raytracer (Ascii Art) by HyperTNTClown - removed empty placeholder arrays
  • knight by krisk - removed a spurious array element
  • Procedural City by Elijah Bodden - converted points to 2D before using toolkit functions
  • Generic 3D Bed Slinger by Joshua Vinod - removed extra arguments

Open PRs

  • cactus jack by Atharv and Aditya - reached out to athrav (also on slack), now fixed
  • cute one-line flower by emma x and sophia x - reached out to emma (also slack DMs)
  • Starry Sky by Ethan W - reached out to ethan (also IRL, we're friends & Hack Club cofounders)

Original description (from #717)

This PR improves error messages significantly:
Line 27: bt.rotate expects argument 1 to be an array of polylines, but got a single polyline

Before this change:
Line 0: undefined is not a function (near '...[o,u]...')

This adds assertations to all of the built-in functions in Blot to throw meaningful errors when the wrong arguments are passed. It also upgrades the stack trace parsing logic, using V8's object representation and a regex built based on the SpiderMonkey and JavaScriptCore source code. Safari (JavaScriptCore) does not keep track of line numbers within eval'd code, so a hack is used to construct a data URL and import it when it is detected to be nessesary.

The previous version of Blot would give unhelpful errors like "t is not defined" on line 0, and line numbers only ever worked on Chrome in some cases. Now, it will give helpful errors explaining what went wrong, pointing to the correct position in the code on any browser.

There is a known issue where, on Safari, the stack does not follow nesting, so if the user defines a function, the error will appear where the function is called instead of within the function, but
there is no way to fix this.

This code is broken, and was reverted. This commit reverts the revert,
so I can work on fixing the code.

This reverts commit bf30801, reversing
changes made to da61aa5.
Fix bugs that were discovered when testing the new error message system
against every gallery function and open PR. It fixes a number of subtle
logic bugs, adds a new "numberArray" type for the bt.noise function, and
improves performance by not checking every element of large arrays.

This commit is a combination of the following 7 commits:

Fix bug in noise.js to satisfy assertions
Make logic for determining the type of an array more accurate and robust
Add numberArray type for the bt.noise function
Correctly mark the second argument to bt.simplify as optional
Make a point count as a numberArray
Fix handling of special case expected types within arrays
Correct the implementation of numberArray to apply to any size of array
…ions

These 9 projects in the gallery were using built-in functions
incorrectly, which triggered the new assertion errors. The changes made
to fix these projects are as follows:

- GSLV.Mk.III by Samrat - removed an extra wrapper array
- Gallifreyan by Shav Kinderlehrer - removed empty placeholder arrays
- tennis racket by ahowden27 - removed extra wrapper arrays
- UnionedPolygons by sosenteam - converted multiple arguments into array
- cloudyFibonacci by Yohance - corrected array access syntax
- Blot Raytracer (Ascii Art) by HyperTNTClown - removed empty
  placeholder arrays
- knight by krisk - removed a spurious array element
- Procedural City by Elijah Bodden - converted points to 2D before using
  toolkit functions
- Generic 3D Bed Slinger by Joshua Vinod - removed extra arguments
Copy link

github-actions bot commented Aug 4, 2024

art/GSLV.Mk.III-Samrat/index.js looks like art! preview it in the editor
art/Gallifreyan/index.js also looks like art! preview it in the editor
art/Generic3DBedSlinger-JustJoshingYa/index.js also looks like art! preview it in the editor
art/UnionedPolygons-sosenteam/index.js also looks like art! preview it in the editor
art/cloudyFibonacci-Yohance/index.js also looks like art! preview it in the editor
art/knight-krisk/index.js also looks like art! preview it in the editor
art/proceduralCity-Elijah/index.js also looks like art! preview it in the editor
art/racket-ahowden27/index.js also looks like art! preview it in the editor
art/raytracer-hypertntclown/index.js also looks like art! preview it in the editor

@qcoral
Copy link
Member

qcoral commented Aug 19, 2024

Going to merge this for now, if it causes issues I will revert!

@qcoral qcoral merged commit 7c67ffb into hackclub:main Aug 19, 2024
1 of 2 checks passed
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.

2 participants