Git Product home page Git Product logo

Comments (8)

fpliger avatar fpliger commented on June 13, 2024

Agree on the overall sentiment (MicroPython error messages needing more clarity)

In the meantime, @laffra do you have a code sample that we can use to reproduce?

from pyscript.

laffra avatar laffra commented on June 13, 2024

from pyscript.

WebReflection avatar WebReflection commented on June 13, 2024

This is not a solution rather a possible workaround to at least understand what kind of object passes through that proxy trap and what is the property name that is accessing it.

This <script> should be the very first script on the page so on top of the <head> or surely before any PyScript code gets a chance to execute.

<script>
($Proxy => {
  globalThis.Proxy = class Proxy {
    constructor(target, handler) {
      const { has } = handler;
      if (has) handler.has = (target, name) => {
        console.warn(`has("${name}") for`, target);
        return has.call(handler, target, name);
      };
      return new $Proxy(target, handler);
    }
  }
})(Proxy);

// in case you'd like to test this:
// 'test' in new Proxy({}, Object.create(Reflect));
// will warn and it will return false
</script>

We are rather after a rewrite of the MicroPython Proxy and I believe "better errors" will be inherently part of the refactoring as currently we have an explicit throw new Error('not implemented') in various proxies traps so tha as soon as any JS tries to understand the shape of a Python object that miserably (currently) fails in MicroPython (only).

edit there was a pretty important missing part of the code.

edit 2 I am assuming the issue with MicroPython is on the main thread, not via worker attribute ... in latter case it's a bit more complicated as I don't think we have a mechanism to patch the JS env there before anything else happens ... but maybe we should in the future for either debugging or fancy patching use cases.

from pyscript.

laffra avatar laffra commented on June 13, 2024

from pyscript.

WebReflection avatar WebReflection commented on June 13, 2024

that's super odd ... let me try an amend

<script>
($Proxy => {
  globalThis.Proxy = class Proxy {
    constructor(target, handler) {
      const { has } = handler;
      if (has) {
        handler = Object.create(handler);
          handler.has = (target, name, ...rest) => {
          if (target._ref)
            console.warn(`has("${name}") for`, target);
          return has.call(handler, target, name, ...rest);
        };
      }
      return new $Proxy(target, handler);
    }
  }
})(Proxy);
</script>

This should be less obtrusive and log only on MicroPython proxy cases.

from pyscript.

laffra avatar laffra commented on June 13, 2024

from pyscript.

WebReflection avatar WebReflection commented on June 13, 2024

Yes, the snippet won't remove the error as that's not possible (as it's backed in MicroPython) but you should read something in console (devtools) ... and by something I mean a warning ... don't you have any warning in console that prints has("...") for anywhere? It's very hard to help further without having a reproducible project to test against though, apologies if my help is actually not helping much.

from pyscript.

WebReflection avatar WebReflection commented on June 13, 2024

This has been fixed in latest MicroPython so this error should not come up anymore.

from pyscript.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.