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

fix: gracefully fail Edge Functions in case of deno binary issues #4685

Merged
merged 20 commits into from
Jun 23, 2022

Conversation

jackiewmacharia
Copy link
Contributor

@jackiewmacharia jackiewmacharia commented Jun 9, 2022

🎉 Thanks for submitting a pull request! 🎉

Summary

Fixes #4621

Requires netlify/edge-bundler#42

netlify dev breaks in case one runs it on a platform (e.g linux aarch64) not yet officially supported by deno, to avoid this we need to gracefully fail Edge Functions making it possible to continue using netlify dev.


To test this:

  • Clone fix/add-error-state-to-after-download branch of edge-bundler; run npm install and npm run build in edge-bundler to set it up; edit CLI's package.json to use the cloned version of edge-bundler eg "@netlify/edge-bundler": "file:../edge-bundler"
  • Break the deno installation process by making the following changes in edge-bundler:
    • comment out this block of code to force the download step to get called each time
    • change this line to if (downloadedVersion !== undefined) { to cause the binary download step to throw an error.
    • change this line to await this.writeVersionFile(downloadedVersion || '') to get past TypeScript type check errors
    • run npm run build to make changes available CLI
  • In a project use the local CLI to run the dev command e.g ~/netlify/cli/bin/run dev
  • It should surface the error without breaking rest of dev command process, test this by accessing a serverless function

Error string for review: › There was a problem setting up the Edge Functions environment and it's unfortunately not possible to run Edge Functions from the CLI on this platform. More on supported platforms here: https://deno.land/manual/getting_started/installation. Error: <error.message from error object>

Screenshot:

Screenshot 2022-06-09 at 18 51 34

For us to review and ship your PR efficiently, please perform the following steps:

  • Open a bug/issue before writing your code 🧑‍💻. This ensures we can discuss the changes and get feedback from everyone that should be involved. If you`re fixing a typo or something that`s on fire 🔥 (e.g. incident related), you can skip this step.
  • Read the contribution guidelines 📖. This ensures your code follows our style guide and
    passes our tests.
  • Update or add tests (if any source code was changed or added) 🧪
  • Update or add documentation (if features were changed or added) 📝
  • Make sure the status checks below are successful ✅

A picture of a cute animal (not mandatory, but encouraged)
cute animal

@jackiewmacharia jackiewmacharia requested a review from a team June 9, 2022 14:44
@jackiewmacharia jackiewmacharia changed the title (fix): gracefully fail Edge Functions in case of deno binary issues fix: gracefully fail Edge Functions in case of deno binary issues Jun 9, 2022
@github-actions
Copy link

github-actions bot commented Jun 9, 2022

📊 Benchmark results

Comparing with 9dffdb0

Package size: 226 MB

⬇️ 0.00% decrease vs. 9dffdb0

^                                                          291 MB  294 MB  294 MB  294 MB  294 MB         
│                                                           ┌──┐    ┌──┐    ┌──┐    ┌──┐    ┌──┐          
│                                                           |  |    |  |    |  |    |  |    |  |          
│                                                           |  |    |  |    |  |    |  |    |  |          
│ ──────────────────────────────────────────────────────────┼──┼────┼──┼────┼──┼────┼──┼────┼──┼──────────
│  226 MB  226 MB  226 MB  226 MB  226 MB  221 MB  221 MB   |  |    |  |    |  |    |  |    |  |   226 MB 
│   ┌──┐    ┌──┐    ┌──┐    ┌──┐    ┌──┐    ┌──┐    ┌──┐    |  |    |  |    |  |    |  |    |  |    ┌──┐  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
└───┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴──>
    T-12    T-11    T-10    T-9     T-8     T-7     T-6     T-5     T-4     T-3     T-2     T-1      T    
Legend

@github-actions github-actions bot added the type: bug code to address defects in shipped code label Jun 9, 2022
Co-authored-by: Daniel Tschinder <231804+danez@users.noreply.github.com>
danez
danez previously approved these changes Jun 10, 2022
Copy link
Contributor

@danez danez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

works 🌻
Screenshot 2022-06-10 at 14 29 16

src/lib/edge-functions/proxy.js Outdated Show resolved Hide resolved
src/lib/edge-functions/proxy.js Outdated Show resolved Hide resolved
src/lib/edge-functions/proxy.js Outdated Show resolved Hide resolved
src/lib/edge-functions/proxy.js Outdated Show resolved Hide resolved
eduardoboucas
eduardoboucas previously approved these changes Jun 15, 2022
@jackiewmacharia
Copy link
Contributor Author

@eduardoboucas suggestions applied and as per usual review reset 😅

Screenshot 2022-06-15 at 22 28 27

[headers.Passthrough]: 'passthrough',
[headers.RequestID]: generateUUID(),
[headers.IP]: LOCAL_HOST,
try {
Copy link
Member

@eduardoboucas eduardoboucas Jun 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry if this wasn't clear in my previous comment, but I was trying to suggest that you only wrap the Promise.all call in the try/catch, not the entire block. Otherwise we're back to the problem of wrapping too much code and potentially swallowing errors.

Something like:

let ops

try {
  ops = await Promise.all([
    getGeoLocation({ mode: geolocationMode, offline, state }),
    server,
  ])
} catch (err) {
  error(err, { exit: false })

  hasServerError = true

  return
}

const [geoLocation, { registry }] = ops

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aaah I see, done.

Copy link
Member

@eduardoboucas eduardoboucas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's looking great! Left just a couple more questions.

src/lib/edge-functions/proxy.js Outdated Show resolved Hide resolved
src/lib/edge-functions/proxy.js Outdated Show resolved Hide resolved
@jackiewmacharia
Copy link
Contributor Author

@eduardoboucas this one is now updated with edge-bundler changes and is now ready.

Copy link
Contributor

@danez danez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@jackiewmacharia jackiewmacharia added automerge Add to Kodiak auto merge queue and removed automerge Add to Kodiak auto merge queue labels Jun 23, 2022
@jackiewmacharia jackiewmacharia enabled auto-merge (squash) June 23, 2022 08:13
@jackiewmacharia jackiewmacharia merged commit 2bdfa82 into main Jun 23, 2022
@jackiewmacharia jackiewmacharia deleted the fix/gracefully-fail-in-case-deno-binary-issue branch June 23, 2022 10:01
Copy link
Member

@eduardoboucas eduardoboucas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work!

bluejacket-c4 pushed a commit to code-423n4/code423n4.com that referenced this pull request Mar 9, 2023
the backstory is that Netlify CLI has trouble installing deno on my 64-bit ARM Linux VM (aarch64), see details on netlify/cli#4685 via netlify/cli#4621

unfortunately this didn't really fix the problem for me (should have
been part of the 10.6.2 netlify-cli release
netlify/cli#4729) but seems to be what other
devs are using locally anyway so it seemed reasonable to bump it here

the new @types/node dev dep is to avoid a (new?) unmet peer
dependency warning with the new cli package
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug code to address defects in shipped code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Android] Netlify dev failed with redirects/edge functions
4 participants