# Detecting endless loop as an error

**URL:** <https://talk.observablehq.com/t/detecting-endless-loop-as-an-error/8450>\
**Category:** Feedback\
**Created:** [November 3, 2023, 4:04pm UTC](https://talk.observablehq.com/t/detecting-endless-loop-as-an-error/8450 "2023-11-03T16:04:28Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![abitrolly](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/abitrolly/32/7214_2.png) [@abitrolly](https://talk.observablehq.com/u/abitrolly)\
**Post date:** [November 3, 2023, 4:04pm UTC](https://talk.observablehq.com/t/detecting-endless-loop-as-an-error/8450/1 "2023-11-03T16:04:28Z")

</div>

Would it be nice if Observable detected endless loops and highlighted them as errors?

 ![image](https://canada1.discourse-cdn.com/flex030/uploads/observablehq/original/2X/b/b33eeab91ae3a65fcbf25a69b625a65515eac11e.png)

This loop has no chance to be completed.

But because it is constantly spinning, it gives the impression that Observable hangs and/or makes a heavy load on browser.

> **[Debug: The infinite loop](https://observablehq.com/@abitrolly/debug-the-infinite-loop)**
>
> meh

---

<div class="post-metadata">

**Author:** ![mythmon](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/mythmon/32/8504_2.png) [@mythmon](https://talk.observablehq.com/u/mythmon)\
**Post date:** [November 3, 2023, 4:28pm UTC](https://talk.observablehq.com/t/detecting-endless-loop-as-an-error/8450/2 "2023-11-03T16:28:17Z")

</div>

These aren’t actually infinite loops. The cell isn’t constantly running, it is actually waiting for the value of `some_markdown`. The `viewof` operator expects it’s argument to have a `.value` property, which turns into the value of the cell used elsewhere. Since `md` doesn’t assign a value property, Observable waits for it to appear. So if anything, the first cell in your notebook should be the highlighted one, not the two you circled.

True infinite loops are possible, but extremely tricky to do much about. If the worker is running an infinite loop, it won’t stop to receive messages to stop running that infinite loop. We mostly rely on browsers’ “slow script” warnings for this.

Perhaps if a cell takes longer than some threshold it could be flagged as slow, but some cells intentionally take a very long time to resolve, like cells that wait for user input. It would be hard to tune right.

---

<div class="post-metadata">

**Author:** ![abitrolly](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/abitrolly/32/7214_2.png) [@abitrolly](https://talk.observablehq.com/u/abitrolly)\
**Post date:** [November 3, 2023, 11:28pm UTC](https://talk.observablehq.com/t/detecting-endless-loop-as-an-error/8450/3 "2023-11-03T23:28:39Z")

</div>

> [@mythmon](#):
>
> The `viewof` operator expects it’s argument to have a `.value` property

There is no way for user to know that the reason for the hang is that `viewof` expects `.value`, and there is no way for the user to know that the line that calls `some_markdown` expects `.value`.

I can ask questions in the forum once in a while, but most user bounce. So the more they can learn from error messages, the higher will be their conversion rate.

1. Learn from errors
2. Know what to do from errors
3. Automate the fixes, provide even more descriptive errors

In ideal (programming) environment, each error is a clear choice between clear actions.

---

<div class="post-metadata">

**Author:** ![mootari](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/mootari/32/581_2.png) [@mootari](https://talk.observablehq.com/u/mootari)\
**Post date:** [November 4, 2023, 12:04pm UTC](https://talk.observablehq.com/t/detecting-endless-loop-as-an-error/8450/4 "2023-11-04T12:04:02Z")

</div>

@abitrolly There is no error here, this particular behavior is by design. Cells that depend on a `viewof` cell don’t immediately resolve if the view’s initial value is `undefined` (viewof uses [Generators.input()](https://github.com/observablehq/stdlib#Generators_input) from Observable’s Standard Library under the hood).

It’s the same as having a cell return a promise that never resolves:

```js
new Promise(()=>{})

```

I do however see that [the docs](https://observablehq.com/@observablehq/views) don’t yet mention the behavior.

---

<div class="post-metadata">

**Author:** ![Cobus](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/cobus/32/9670_2.png) [@Cobus](https://talk.observablehq.com/u/Cobus)\
**Post date:** [November 4, 2023, 3:59pm UTC](https://talk.observablehq.com/t/detecting-endless-loop-as-an-error/8450/5 "2023-11-04T15:59:07Z")

</div>

@abitrolly  
I can see that this behavior is not totally obvious. I would love to learn a little bit more about what you were trying to do with that first cell where you used the `viewof`, Since that is really meant to be used with an input that returns the value as Michael described.

---

<div class="post-metadata">

**Author:** ![abitrolly](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/abitrolly/32/7214_2.png) [@abitrolly](https://talk.observablehq.com/u/abitrolly)\
**Post date:** [November 8, 2023, 2:57pm UTC](https://talk.observablehq.com/t/detecting-endless-loop-as-an-error/8450/6 "2023-11-08T14:57:37Z")

</div>

@Cobus thanks for the confirmation of the non-intuitive behavior. I was trying to debug the error `RuntimeError: e.addEventListener is not a function`.

 ![image](https://canada1.discourse-cdn.com/flex030/uploads/observablehq/original/2X/6/6a76b2e28ed4643cdec5e012b7cc144f294cf65c.png)

The thing is, I want `zipStream` cell to show the message if there is no input, and if there is input then show the value of fetch. My mistake was using `viewof`. I probably wanted to show some other info instead of `zipStream = Blob {}` when the file is fetched.

The problem is - there is no way to understand what is going on by looking at the errors. One need a lot of prior knowledge about to debug and resolve such errors. To understand that this specific problem is in misuse of `viewof` in a certain condition.
