question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

An app would hang if attempting "import nonexistent_module" from CDN

See original GitHub issue

An app would hang if attempting “import nonexistent_module” from CDN, due to uncaught error in brython.js. Is it possible to have brython raise an ImportError instead?

Repro:

  • Content in index.html

    ...
    <script src="https://cdnjs.cloudflare.com/ajax/libs/brython/3.9.1/brython.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/brython/3.9.1/brython_stdlib.min.js"></script>
    <script type="text/python" src="main.py"></script>
    ...
    
  • Content in main.py

    try:
        import optional_module
    except ImportError:
        print("That is fine")
    

Expects to see “That is fine” in the console.

What actually happened is that the app hangs, with the following output on the browser console. The first 2 or 3 lines are expected, but can Brython or javascript recover from a “Cross-Origin Request Blocked” request?

Error 404 means that Python module cowsay was not found at url http://localhost:8000/optional_module.py
Error 404 means that Python module cowsay was not found at url http://localhost:8000/__init__/optional_module.py
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://cdnjs.cloudflare.com/ajax/libs/brython/3.9.1/Lib/site-packages/optional_module.py?v=1615571704659. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing).
Javascript exception: DOMException: A network error occurred.
...
test is js exc is recursion error DOMException: A network error occurred. NetworkError: A network error occurred.
...
Uncaught Error: 
    $factory https://cdnjs.cloudflare.com/ajax/libs/brython/3.9.1/brython.min.js line 1 > eval:1
    loop https://cdnjs.cloudflare.com/ajax/libs/brython/3.9.1/brython.min.js:1
    onsuccess https://cdnjs.cloudflare.com/ajax/libs/brython/3.9.1/brython.min.js:1
    onsuccess https://cdnjs.cloudflare.com/ajax/libs/brython/3.9.1/brython.min.js:1
brython.min.js line 1 > eval:1:7500
    $factory https://cdnjs.cloudflare.com/ajax/libs/brython/3.9.1/brython.min.js line 1 > eval:1
    loop https://cdnjs.cloudflare.com/ajax/libs/brython/3.9.1/brython.min.js:1
    onsuccess https://cdnjs.cloudflare.com/ajax/libs/brython/3.9.1/brython.min.js:1
    onsuccess https://cdnjs.cloudflare.com/ajax/libs/brython/3.9.1/brython.min.js:1

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
PierreQuentelcommented, Mar 16, 2021

I did try this Javascript program:

var url = "https://cdnjs.cloudflare.com/ajax/libs/brython/3.9.1/Lib/site-packages/optional_module.py?v=1615916897909"
var xhr = new XMLHttpRequest()
xhr.open('GET', url)
console.log("try")
try{
  xhr.send()
  console.log("no JS exception")
}catch(err){
  console.log("error", err)
}

The console prints this:

try
no JS exception
XHRGEThttps://cdnjs.cloudflare.com/ajax/libs/brython/3.9.1/Lib/site-packages/optional_module.py?v=1615916897909
CORS Missing Allow Origin

Blocage d’une requête multiorigines (Cross-Origin Request) : la politique « Same Origin » ne permet pas de consulter la ressource distante située sur https://cdnjs.cloudflare.com/ajax/libs/brython/3.9.1/Lib/site-packages/optional_module.py?v=1615916897909. Raison : l’en-tête CORS « Access-Control-Allow-Origin » est manquant.
0reactions
rayluocommented, Jun 28, 2021

Interestingly, I notice that the ImportError can be caught now, and the except clause can be run. Last time @PierreQuentel and I both tested this issue 3 months ago, it did not work at that time. The only difference today is I run it with a newer version of browser. Just a FYI.

Read more comments on GitHub >

github_iconTop Results From Across the Web

OneNote hangs while importing notes - Microsoft Community
I am OK with losing that content I tried to import. I just want to get into the app so that I can...
Read more >
If an app on your iPhone or iPad stops responding, closes ...
If an app on your iPhone or iPad doesn't work as expected, try this. ... When you do this, you might lose data...
Read more >
Crash when importing a LandXML file into AutoCAD ...
When attempting to import a LandXML file into AutoCAD Architecture or MEP, the application crashes.
Read more >
Studio crashes and hangs when the Import button is selected ...
Try either clicking on the Studio application tab on the Windows task bar or pressing ALT-TAB on your keyboard to cycle through the...
Read more >
How do you prevent Lumion from hanging or crashing when ...
1. Here's how. If you try to import a model that is too detailed for your computer, Lumion may sometimes hang or run...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found