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

JS C@E build error "too much recursion" #361

Closed
JakeChampion opened this issue Jul 31, 2021 · 7 comments
Closed

JS C@E build error "too much recursion" #361

JakeChampion opened this issue Jul 31, 2021 · 7 comments
Labels
bug Something isn't working

Comments

@JakeChampion
Copy link
Collaborator

Version

Please paste the output of fastly version here.

Fastly CLI version 0.36.0 (dd0b7d9)
Built with go version go1.16.6 linux/amd64

What happened

I ran fastly compute serve --verbose and expected the project to build but instead came across this error:

Fastly API token provided via config file
Fastly API endpoint: https://api.fastly.com
Verifying package manifest...
Verifying local javascript toolchain...
Checking if npm is installed...
Found npm at /Users/jake.champion/.volta/bin/npm
Found package.json at /Users/jake.champion/Code/js/package.json
Checking if @fastly/js-compute is installed...
Found js-compute-runtime at /Users/jake.champion/Code/js/node_modules/.bin/js-compute-runtime
Building package using javascript toolchain...

compute-starter-kit-javascript-default@0.1.0 prebuild
webpack

asset index.js 104 KiB [emitted] [minimized] (name: main)
runtime modules 1.13 KiB 5 modules
modules by path ./node_modules/core-js/ 99.7 KiB
modules by path ./node_modules/core-js/internals/.js 52.6 KiB 80 modules
modules by path ./node_modules/core-js/modules/
.js 46.9 KiB 5 modules
./node_modules/core-js/web/url.js 184 bytes [built] [code generated]
modules by path ./node_modules/semver/ 55.8 KiB 44 modules
modules by path ./node_modules/@financial-times/ 67.9 KiB
./node_modules/@financial-times/polyfill-useragent-normaliser/lib/normalise-user-agent.js 17.4 KiB [built] [code generated]
./node_modules/@financial-times/useragent_parser/lib/ua_parser.js 50.5 KiB [built] [code generated]
modules by path ./node_modules/yallist/*.js 8.42 KiB
./node_modules/yallist/yallist.js 8.21 KiB [built] [code generated]
./node_modules/yallist/iterator.js 207 bytes [built] [code generated]
./src/index.js 2.02 KiB [built] [code generated]
./node_modules/lru-cache/index.js 7.99 KiB [built] [code generated]

WARNING in configuration
The 'mode' option has not been set, webpack will fallback to 'production' for this value.
Set 'mode' option to 'development' or 'production' to enable defaults for each environment.
You can also set it to 'none' to disable any default behavior. Learn more: https://webpack.js.org/configuration/mode/

webpack 5.37.1 compiled with 1 warning in 2153 ms

compute-starter-kit-javascript-default@0.1.0 build
js-compute-runtime --skip-pkg bin/index.js bin/main.wasm

Exception while evaluating JS: (new InternalError("too much recursion", ""))

Error: failed to initialize JS

Caused by:
0: the wizer.initialize function trapped
1: Exited with i32 exit status 1
wasm backtrace:
0: 0x3eb075 - !<wasm function 8535>
1: 0x3eb98a - !<wasm function 8546>
2: 0x13f2d - !<wasm function 215>
3: 0x13abf - !<wasm function 213>
4: 0x14111 - !<wasm function 217>
note: run with WASMTIME_BACKTRACE_DETAILS=1 environment variable to display more information

Wizer failed with status: exit status: 1

Creating package archive...

SUCCESS: Built javascript package js (pkg/js.tar.gz)

Checking latest Viceroy release...
Checking installed Viceroy version...
Running local server...
Wasm file: bin/main.wasm
Manifest: /Users/jake.champion/Code/js/fastly.toml

error: Invalid value for '': No such file or directory (os error 2)

ERROR: error during execution process:
error: Invalid value for '': No such file or directory (os error 2).

If you believe this error is the result of a bug, please file an issue: https://github.com/fastly/cli/issues/new?labels=bug&template=bug_report.md

The code which caused this error to occur is this:

/// <reference types="@fastly/js-compute" />
import * as UA from "@financial-times/polyfill-useragent-normaliser";
const normalizeUserAgent = UA.normalize;
addEventListener('fetch', async function handleRequest(event) {

  // Get the client request from the event
  let req = event.request;

  let headers = new Headers();
  headers.set('Content-Type', 'text/html; charset=utf-8');
  headers.set('normalized-user-agent', normalizeUserAgent(req.headers.get('user-agent')));
  let response = new Response(normalizeUserAgent(req.headers.get('user-agent')), {
    status: 200,
    headers
  });
  // Send the response back to the client.
  event.respondWith(response);
  return;
});
@JakeChampion JakeChampion added the bug Something isn't working label Jul 31, 2021
@JakeChampion
Copy link
Collaborator Author

I believe the problem stems from the @financial-times/useragent_parser package and it doing too many reassignments in the file ./lib/ua_parser.js -- https://unpkg.com/@financial-times/useragent_parser@1.6.0/lib/ua_parser.js

I've rewritten this file to not do reassignments and it now compiles

@JakeChampion
Copy link
Collaborator Author

This is the smallest reproducible example I can make. If you remove one of the else if blocks then it compiles. If you change all the assignments to the family variable to the same value such as Math.random() then it compiles.

/// <reference types="@fastly/js-compute" />

addEventListener('fetch', async function handleRequest() {
  let ua = "";
  let family;
  let result;
  if (result = /a/.exec(ua)) { family = result[1];
  } else if (result = /a/.exec(ua)) { family = Math.random();
  } else if (result = /a/.exec(ua)) { family = result[1];
  } else if (result = /a/.exec(ua)) { family = Math.random();
  } else if (result = /a/.exec(ua)) { family = result[1];
  } else if (result = /a/.exec(ua)) { family = Math.random();
  } else if (result = /a/.exec(ua)) { family = result[1];
  } else if (result = /a/.exec(ua)) { family = Math.random();
  } else if (result = /a/.exec(ua)) { family = result[1];
  } else if (result = /a/.exec(ua)) { family = Math.random();
  } else if (result = /a/.exec(ua)) { family = result[1];
  } else if (result = /a/.exec(ua)) { family = Math.random();
  } else if (result = /a/.exec(ua)) { family = result[1];
  } else if (result = /a/.exec(ua)) { family = Math.random();
  } else if (result = /a/.exec(ua)) { family = result[1];
  } else if (result = /a/.exec(ua)) { family = Math.random();
  } else if (result = /a/.exec(ua)) { family = result[1];
  } else if (result = /a/.exec(ua)) { family = Math.random();
  } else if (result = /a/.exec(ua)) { family = result[1];
  } else if (result = /a/.exec(ua)) { family = Math.random();
  } else if (result = /a/.exec(ua)) { family = result[1];
  } else if (result = /a/.exec(ua)) { family = Math.random();
  } else if (result = /a/.exec(ua)) { family = result[1];
  } else if (result = /a/.exec(ua)) { family = Math.random();
  } else if (result = /a/.exec(ua)) { family = result[1];
  } else if (result = /a/.exec(ua)) { family = Math.random();
  } else if (result = /a/.exec(ua)) { family = result[1];
  } else if (result = /a/.exec(ua)) { family = Math.random();
  } else if (result = /a/.exec(ua)) { family = result[1];
  } else if (result = /a/.exec(ua)) { family = Math.random();
  } else if (result = /a/.exec(ua)) { family = result[1];
  } else if (result = /a/.exec(ua)) { family = Math.random();
  } else if (result = /a/.exec(ua)) { family = result[1];
  } else if (result = /a/.exec(ua)) { family = Math.random();
  } else if (result = /a/.exec(ua)) { family = result[1];
  } else if (result = /a/.exec(ua)) { family = Math.random();
  } else if (result = /a/.exec(ua)) { family = result[1];
  } else if (result = /a/.exec(ua)) { family = Math.random();
  } else if (result = /a/.exec(ua)) { family = result[1];
  } else if (result = /a/.exec(ua)) { family = Math.random();
  } else if (result = /a/.exec(ua)) { family = result[1];
  } else if (result = /a/.exec(ua)) { family = Math.random();
  } else if (result = /a/.exec(ua)) { family = result[1];
  } else if (result = /a/.exec(ua)) { family = Math.random();
  } else if (result = /a/.exec(ua)) { family = result[1];
  } else if (result = /a/.exec(ua)) { family = Math.random();
  } else if (result = /a/.exec(ua)) { family = result[1];
  } else if (result = /a/.exec(ua)) { family = Math.random();
  } else if (result = /a/.exec(ua)) { family = result[1];
  } else if (result = /a/.exec(ua)) { family = Math.random();
  } else if (result = /a/.exec(ua)) { family = result[1];
  } else if (result = /a/.exec(ua)) { family = Math.random();
  } else if (result = /a/.exec(ua)) { family = result[1];
  } else if (result = /a/.exec(ua)) { family = Math.random();
  } else if (result = /a/.exec(ua)) { family = result[1];
  } else if (result = /a/.exec(ua)) { family = Math.random();
  } else if (result = /a/.exec(ua)) { family = result[1];
  } else if (result = /a/.exec(ua)) { family = Math.random();
  } else if (result = /a/.exec(ua)) { family = result[1];
  } else if (result = /a/.exec(ua)) { family = Math.random();
  } else if (result = /a/.exec(ua)) { family = result[1];
  } else if (result = /a/.exec(ua)) { family = Math.random();
  } else if (result = /a/.exec(ua)) { family = result[1];
  } else if (result = /a/.exec(ua)) { family = Math.random();
  } else if (result = /a/.exec(ua)) { family = result[1];
  } else if (result = /a/.exec(ua)) { family = Math.random();
  } else if (result = /a/.exec(ua)) { family = result[1];
  } else if (result = /a/.exec(ua)) { family = Math.random();
  } else if (result = /a/.exec(ua)) { family = result[1];
  } else if (result = /a/.exec(ua)) { family = Math.random();
  } else if (result = /a/.exec(ua)) { family = result[1];
  } else if (result = /a/.exec(ua)) { family = Math.random();
  } else if (result = /a/.exec(ua)) { family = result[1];
  } else if (result = /a/.exec(ua)) { family = Math.random();
  } else if (result = /a/.exec(ua)) { family = result[1];
  } else if (result = /a/.exec(ua)) { family = Math.random();
  } else if (result = /a/.exec(ua)) { family = result[1];
  } else if (result = /a/.exec(ua)) { family = Math.random();
  } else if (result = /a/.exec(ua)) { family = result[1];
  } else if (result = /a/.exec(ua)) { family = Math.random();
  } else if (result = /a/.exec(ua)) { family = result[1];
  } else if (result = /a/.exec(ua)) { family = Math.random();
  } else if (result = /a/.exec(ua)) { family = result[1];
  } else if (result = /a/.exec(ua)) { family = Math.random();
  } else if (result = /a/.exec(ua)) { family = result[1];
  } else if (result = /a/.exec(ua)) { family = Math.random();
  } else if (result = /a/.exec(ua)) { family = result[1];
  } else if (result = /a/.exec(ua)) { family = Math.random();
  } else if (result = /a/.exec(ua)) { family = result[1];
  } else if (result = /a/.exec(ua)) { family = Math.random();
  } else if (result = /a/.exec(ua)) { family = result[1];
  } else if (result = /a/.exec(ua)) { family = Math.random();
  } else if (result = /a/.exec(ua)) { family = result[1];
  } else if (result = /a/.exec(ua)) { family = Math.random();
  } else if (result = /a/.exec(ua)) { family = result[1];
  } else if (result = /a/.exec(ua)) { family = Math.random();
  } else if (result = /a/.exec(ua)) { family = result[1];
  } else if (result = /a/.exec(ua)) { family = Math.random();
  } else if (result = /a/.exec(ua)) { family = result[1];
  } else if (result = /a/.exec(ua)) { family = Math.random();
  } else if (result = /a/.exec(ua)) { family = result[1];
  } else if (result = /a/.exec(ua)) { family = Math.random();
  } else if (result = /a/.exec(ua)) { family = result[1];
  } else if (result = /a/.exec(ua)) { family = Math.random();
  } else if (result = /a/.exec(ua)) { family = result[1];
  } else if (result = /a/.exec(ua)) { family = Math.random();
  } else if (result = /a/.exec(ua)) { family = result[1];
  } else if (result = /a/.exec(ua)) { family = Math.random();
  } else if (result = /a/.exec(ua)) { family = result[1];
  } else if (result = /a/.exec(ua)) { family = Math.random();
  } else if (result = /a/.exec(ua)) { family = result[1];
  } else if (result = /a/.exec(ua)) { family = Math.random();
  } else if (result = /a/.exec(ua)) { family = result[1];
  } else if (result = /a/.exec(ua)) { family = Math.random();
  } else if (result = /a/.exec(ua)) { family = result[1];
  } else if (result = /a/.exec(ua)) { family = Math.random();
  } else if (result = /a/.exec(ua)) { family = result[1];
  } else if (result = /a/.exec(ua)) { family = Math.random();
  } else if (result = /a/.exec(ua)) { family = result[1];
  } else if (result = /a/.exec(ua)) { family = Math.random();
  } else if (result = /a/.exec(ua)) { family = result[1];
  } else if (result = /a/.exec(ua)) { family = Math.random();
  } else if (result = /a/.exec(ua)) { family = result[1];
  } else if (result = /a/.exec(ua)) { family = Math.random();
  } else if (result = /a/.exec(ua)) { family = result[1];
  } else if (result = /a/.exec(ua)) { family = Math.random();
  } else if (result = /a/.exec(ua)) { family = result[1];
  } else if (result = /a/.exec(ua)) { family = Math.random();
  } else if (result = /a/.exec(ua)) { family = result[1];
  } else if (result = /a/.exec(ua)) { family = Math.random();
  } else if (result = /a/.exec(ua)) { family = result[1];
  } else if (result = /a/.exec(ua)) { family = Math.random();
  } else if (result = /a/.exec(ua)) { family = result[1];
  } else if (result = /a/.exec(ua)) { family = Math.random();
  } else if (result = /a/.exec(ua)) { family = result[1];
  } else if (result = /a/.exec(ua)) { family = Math.random();
  } else if (result = /a/.exec(ua)) { family = result[1];
  } else if (result = /a/.exec(ua)) { family = Math.random();
  } else if (result = /a/.exec(ua)) { family = result[1];
  } else if (result = /a/.exec(ua)) { family = Math.random();
  } else if (result = /a/.exec(ua)) { family = result[1];
  } else if (result = /a/.exec(ua)) { family = Math.random();
  } else if (result = /a/.exec(ua)) { family = result[1];
  } else if (result = /a/.exec(ua)) { family = Math.random();
  } else if (result = /a/.exec(ua)) { family = result[1];
  } else if (result = /a/.exec(ua)) { family = Math.random();
  } else if (result = /a/.exec(ua)) { family = result[1];
  } else if (result = /a/.exec(ua)) { family = Math.random();
  } else if (result = /a/.exec(ua)) { family = result[1];
  } else if (result = /a/.exec(ua)) { family = Math.random();
  } else if (result = /a/.exec(ua)) { family = result[1];
  } else if (result = /a/.exec(ua)) { family = Math.random();
  } else if (result = /a/.exec(ua)) { family = result[1];
  } else if (result = /a/.exec(ua)) { family = Math.random();
  } else if (result = /a/.exec(ua)) { family = result[1];
  } else if (result = /a/.exec(ua)) { family = Math.random();
  } else if (result = /a/.exec(ua)) { family = result[1];
  } else if (result = /a/.exec(ua)) { family = Math.random();
  } else if (result = /a/.exec(ua)) { family = result[1];
  } else if (result = /a/.exec(ua)) { family = Math.random();
  } else if (result = /a/.exec(ua)) { family = result[1];
  } else if (result = /a/.exec(ua)) { family = Math.random();
  } else if (result = /a/.exec(ua)) { family = result[1];
  }
  return;
});

@Integralist
Copy link
Collaborator

Thanks @JakeChampion I'll investigate why the CLI didn't stop the 'build' process once Wiser had reported an error, but I believe the rest of the comments in that issue are best discussed here >> fastly/js-compute-runtime#1

@yniGannett
Copy link

Similar issue there, when I run fastly compute build, it showed a successful build. But when I run fastly compute build --verbose, it showed the error, but build result is still successful.

Log: start javascript
Exception while evaluating JS: (new Error("The Dictionary builtin can only be used during request handling, not during initialization", "<stdin>", 1))
  @<stdin>:1:34985
  @<stdin>:1:37596
  @<stdin>:1:37681

Error: failed to initialize JS

Caused by:
    0: the `wizer.initialize` function trapped
    1: Exited with i32 exit status 1
       wasm backtrace:
           0: 0x3f322f - <unknown>!<wasm function 8860>
           1: 0x3f3af3 - <unknown>!<wasm function 8870>
           2: 0x1ae1a - <unknown>!<wasm function 278>
           3: 0x1abb2 - <unknown>!<wasm function 276>
           4: 0x1b0fe - <unknown>!<wasm function 281>
       note: run with `WASMTIME_BACKTRACE_DETAILS=1` environment variable to display more information

Wizer failed with status: exit status: 1

Creating package archive...

SUCCESS: Built javascript package sre-javascript-graphql-poc (pkg/sre-javascript-graphql-poc.tar.gz)

@Integralist
Copy link
Collaborator

@JakeChampion just circling back around to this and it looks like a bunch of build refactoring and logic changes I made over the last few months may have incidentally resolved the issue with compilation errors not causing the build to fail.

For example, using your example:

import * as UA from "@financial-times/polyfill-useragent-normaliser";
const normalizeUserAgent = UA.normalize;
addEventListener('fetch', async function handleRequest(event) {

  // Get the client request from the event
  let req = event.request;

  let headers = new Headers();
  headers.set('Content-Type', 'text/html; charset=utf-8');
  headers.set('normalized-user-agent', normalizeUserAgent(req.headers.get('user-agent')));
  let response = new Response(normalizeUserAgent(req.headers.get('user-agent')), {
    status: 200,
    headers
  });
  // Send the response back to the client.
  event.respondWith(response);
  return;
});

The output I see now with latest main branch is:

Screenshot 2022-01-13 at 14 00 45

@JakeChampion
Copy link
Collaborator Author

@Integralist it looks to compile correctly for me now when using the latest fastly cli

❯ fastly compute build
✓ Initializing...
✓ Verifying package manifest...
✓ Verifying local javascript toolchain...
✓ Building package using javascript toolchain...
✓ Creating package archive...

SUCCESS: Built package 'js-test' (pkg/js-test.tar.gz)

@Integralist
Copy link
Collaborator

Awesome. I'm going to close of this issue for now. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants