The Observable runtime tries to access a property named 'then' of my Proxy object

I’m using a Proxy object in order to throw exeptions when nonexistent properties are accessed. The Observable runtime tries to access a property named then, which does not exist and hence my code throws an exception. I guess that Observable is assuming that my object is a Promise.

The code works if the exception throwing is removed or if a normal object is used instead of the proxy object; See comments in the code.

Wrapping the proxy object in a promise didn’t help:

Defining dummy then and next properties as a workaround works:

Am I doing something wrong or is it the Observable runtime?

Behind the scenes (but in our OSS code - here’s one of the instances), we run Promise.resolve on returned node values. That turns static values into promises, and if the object is ‘thenable’, it’ll try to reach inside of what it assumes is a Promise and run that.

I’ll chat with the folks if there’s another way around this, but I think this would generally follow the same pattern as you’d use if you wanted to pass a Promise object around without evaluating it: you can wrap it either as a property or make it the return value of a functor: here’s an example - https://beta.observablehq.com/d/61aa3f76a0121898 . The one thing that won’t work for that wrapping trick is… a Promise, because Promise.resolve will just resolve any number of layers of Promises.

1 Like

Thanks for the solutions Tom. I didn’t realize that this wasn’t specific to Observable. For those reading along, I made this fiddle to show that it’s a general problem.