jmoenig / Snap

a visual programming language inspired by Scratch
http://snap.berkeley.edu
GNU Affero General Public License v3.0
1.47k stars 739 forks source link

"Reporter didn't report" error isn't catchable #3327

Open brianharvey opened 3 months ago

brianharvey commented 3 months ago

untitled script pic (2) untitled script pic (3)

(By the way, if I leave out the MOVE block, then BAD REPORTER reports 0 instead of not reporting. I think that's a bug, too, but less important.)

The reason is this, in threads.js:

Process.prototype.expectReport = function () {
    this.handleError(new Error("reporter didn't report"));
};

which I think should be

Process.prototype.expectReport = function () {
    throw new Error("reporter didn't report");
};

... but when I try that, it causes an infinite loop, so I'll let someone else debug it. :)

This sounds like a minor problem, except that it's standing in the way of the logic programming library development. :(

jmoenig commented 3 months ago

Error catching isn't part of Snap's functionality, only throwing errors. We don't (yet) have first class exceptions, not even first class processes/threads.

brianharvey commented 3 months ago

Aw, c'mon, we advertise a library for it. I don't recall you objecting to that one, although I may be forgetting. Anyway, it's just this one error that we can't catch. That ought to be fixable.

PS We don't have first class processes, exactly, but we do have first class continuations, which sort of comes to the same thing.

jmoenig commented 3 months ago

Why do you need to catch it, could you explain? You're not using metaprogramming to ad-hoc define new reporters, or are you?

brianharvey commented 3 months ago

Actually one of qw23's goals is to avoid metaprogramming.

The goal is to build something like mapreduce's mapper function, which can return multiple values, including the case of no values, in which case that input is dropped from the result.

Ideally the user would be enabled to insert any expression, such as ddd0b14073eaf5c54c0c565d440c5a8b2359f54e or 26ac7d3691c1268253b6774dbd8fd2e0a18e825f. The latter, however, always reports something (i.e. the value of the input). I tried a special version if (condition) then (expression), not reporting anything if the condition fails. However that causes an error (“hmm ... reporter didn’t report”) that can’t be caught by safely try … any suggestions?

If you want more context, you can start here: https://forum.snap.berkeley.edu/t/logic-programming-library-development-log/13828/108 starting in the middle of that post with the heading "Multiplicate stream items." But it's a pretty long thread, even just the part leading up to this issue.