Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Devex: Console.log an explanation of CORS issues to clarify why, e.g., zips from GitHub urls cant be downloaded #1205

Closed
helgatheviking opened this issue Apr 5, 2024 · 5 comments · Fixed by #1281
Assignees
Milestone

Comments

@helgatheviking
Copy link

I have a little snippet I would like to install to make my plugin's playground preview look nicer. So I pushed it to github and created a zip release for it.

I've added a step to my blueprint.json that attempts to install the plugin from a URL resource:

        {
            "step": "installPlugin",
            "pluginZipFile": {
                "resource": "url",
                "url": "https:\/\/github.com\/helgatheviking\/simple-user-listing-demo-avatars\/releases\/download\/1.0.0\/simple-user-listing-demo-avatars.1.0.0.zip"
            },
            "options": {
                "activate": true
            }
        },

But the playground fails even though I have networking turned on

"features": {
        "networking": true
    },

here's the error I see in the console (which looks like a networking failure)

Uncaught (in promise) Error: Error when executing the blueprint step #2 ({"step":"installPlugin","pluginZipFile":{"resource":"url","url":"https://github.com/helgatheviking/simple-user-listing-demo-avatars/releases/download/1.0.0/simple-user-listing-demo-avatars.1.0.0.zip"},"options":{"activate":true}}) : NetworkError when attempting to fetch resource.
    run https://playground.wordpress.net/assets/config-e3ffca93.js:624
    runBlueprintSteps https://playground.wordpress.net/assets/config-e3ffca93.js:624
    startPlaygroundWeb https://playground.wordpress.net/assets/config-e3ffca93.js:628
    RP https://playground.wordpress.net/assets/main-86fb9d4a.js:32
    sl https://playground.wordpress.net/assets/client-a736c30d.js:40
    Gn https://playground.wordpress.net/assets/client-a736c30d.js:40
    gd https://playground.wordpress.net/assets/client-a736c30d.js:40
    E https://playground.wordpress.net/assets/client-a736c30d.js:25
    ot https://playground.wordpress.net/assets/client-a736c30d.js:25
    EventHandlerNonNull* https://playground.wordpress.net/assets/client-a736c30d.js:25
    <anonymous> https://playground.wordpress.net/assets/client-a736c30d.js:25
Caused by: TypeError: NetworkError when attempting to fetch resource.
@adamziel
Copy link
Collaborator

adamziel commented Apr 5, 2024

@helgatheviking you can load files using the https://raw.githubusercontent.com/ URL. The culprit are CORS header – the site must serve Access-Control-Allow-Origin: * and github.com doesn't do that. But raw.githubusercontent.com does. Unfortunately, the latter doesn't support serving releases :-( But if you upload that zip as a file to the repo, you'll be able to load it.

Also – I just wrote this guide on Blueprints. It might help you and I would be very interested in your feedback:

WordPress/blueprints#5

@adamziel adamziel closed this as completed Apr 5, 2024
@adamziel adamziel reopened this Apr 5, 2024
@adamziel
Copy link
Collaborator

adamziel commented Apr 5, 2024

Actually, let's reuse this issue to explain the downloading issue right in the error message in the console.

@adamziel adamziel changed the title Does the installPlugin step support zips from GitHub urls? Update the installPlugin error to explain why zips from GitHub urls cant be downloaded Apr 5, 2024
@adamziel adamziel added this to the Zero Crashes milestone Apr 5, 2024
@helgatheviking
Copy link
Author

Ah ok. I didn't know there would be a difference. That's not ideal, but doable to get this working.

What about uploading a single file:

https://raw.githubusercontent.com/helgatheviking/simple-user-listing-demo-avatars/trunk/simple-user-listing-demo-avatars.php

is that possible?

@adamziel
Copy link
Collaborator

adamziel commented Apr 5, 2024

It is! Check that crash course for details on how to do it, it won't be the installPlugin step

@helgatheviking
Copy link
Author

Got it working!

@adamziel adamziel changed the title Update the installPlugin error to explain why zips from GitHub urls cant be downloaded Devex: Console.log an explanation of CORS issues to explain, e.g., why zips from GitHub urls cant be downloaded Apr 12, 2024
@adamziel adamziel changed the title Devex: Console.log an explanation of CORS issues to explain, e.g., why zips from GitHub urls cant be downloaded Devex: Console.log an explanation of CORS issues to clarify why, e.g., zips from GitHub urls cant be downloaded Apr 12, 2024
@bgrgicak bgrgicak self-assigned this Apr 19, 2024
bgrgicak added a commit that referenced this issue Apr 24, 2024
Fixes #1205

## What is this PR doing?

It adds an error message for blueprint network errors.

## What problem is it solving?

It will help users identify the root cause of blueprints failing.

## How is the problem addressed?

By returning a custom error message with debug instructions.

## Testing Instructions

- Checkout this branch
- [Open Playground with this
blueprint](http://localhost:5400/website-server/#{%20%22features%22:%20{%20%22networking%22:%20true%20},%20%22steps%22:%20[%20{%20%22step%22:%20%22installPlugin%22,%20%22pluginZipFile%22:%20{%20%22resource%22:%20%22url%22,%20%22url%22:%20%22https://github.com/helgatheviking/simple-user-listing-demo-avatars/releases/download/1.0.0/simple-user-listing-demo-avatars.1.0.0.zip%22%20},%20%22options%22:%20{%20%22activate%22:%20true%20}%20}%20]%20})
- Open the browser console and see the new error 

**Note**: The error is currently displayed multiple times because of
uncaught promises somewhere in the code.

---------

Co-authored-by: Adam Zielinski <adam@adamziel.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants