vscode-edge-devtools icon indicating copy to clipboard operation
vscode-edge-devtools copied to clipboard

AnalyzerError: Cannot read properties of undefined (reading 'getLocation')

Open jSadoski opened this issue 3 years ago • 2 comments

Environment:

  • OS: Windows 10 Pro
  • Extension version (e.g., 1.2.3): 2.0.0

Describe the bug:

Upon opening a .html file (in this case, a Jinja2 template), I get this notification:

image

The output is as follows (redacted my repo name):

Click to expand
Error loading "hint" package from "c:\Repos\my-repo"
Trying to load shared version
Found hint at c:\Users\jsadoski\AppData\Roaming\Code\User\globalStorage\ms-edgedevtools.vscode-edge-devtools\node_modules\hint\dist\src\lib\index.js
c:\Users\jsadoski\AppData\Roaming\Code\User\globalStorage\ms-edgedevtools.vscode-edge-devtools\node_modules\hint\dist\src\lib\analyzer.js:151
                throw new types_1.AnalyzerError(e, error_status_1.AnalyzerErrorStatus.AnalyzeError);
                      ^

AnalyzerError: Cannot read properties of undefined (reading 'getLocation')
    at Analyzer.analyze (c:\Users\jsadoski\AppData\Roaming\Code\User\globalStorage\ms-edgedevtools.vscode-edge-devtools\node_modules\hint\dist\src\lib\analyzer.js:151:23)
    at runNextTicks (node:internal/process/task_queues:61:5)
    at processImmediate (node:internal/timers:437:9)
    at async c:\Users\jsadoski\.vscode\extensions\ms-edgedevtools.vscode-edge-devtools-2.0.0\node_modules\vscode-webhint\dist\src\server.js:1:1214
    at async t.Analyzer.validateTextDocument (c:\Users\jsadoski\.vscode\extensions\ms-edgedevtools.vscode-edge-devtools-2.0.0\node_modules\vscode-webhint\dist\src\server.js:1:1139)
    at async c:\Users\jsadoski\.vscode\extensions\ms-edgedevtools.vscode-edge-devtools-2.0.0\node_modules\vscode-webhint\dist\src\server.js:1:139563 {
  status: 'AnalyzeError'
}
[Info  - 9:36:05 AM] Connection to server got closed. Server will restart.
Error loading "hint" package from "c:\Repos\my-repo"
Trying to load shared version
Found hint at c:\Users\jsadoski\AppData\Roaming\Code\User\globalStorage\ms-edgedevtools.vscode-edge-devtools\node_modules\hint\dist\src\lib\index.js
c:\Users\jsadoski\AppData\Roaming\Code\User\globalStorage\ms-edgedevtools.vscode-edge-devtools\node_modules\hint\dist\src\lib\analyzer.js:151
                throw new types_1.AnalyzerError(e, error_status_1.AnalyzerErrorStatus.AnalyzeError);
                      ^

AnalyzerError: Cannot read properties of undefined (reading 'getLocation')
    at Analyzer.analyze (c:\Users\jsadoski\AppData\Roaming\Code\User\globalStorage\ms-edgedevtools.vscode-edge-devtools\node_modules\hint\dist\src\lib\analyzer.js:151:23)
    at runNextTicks (node:internal/process/task_queues:61:5)
    at processImmediate (node:internal/timers:437:9)
    at async c:\Users\jsadoski\.vscode\extensions\ms-edgedevtools.vscode-edge-devtools-2.0.0\node_modules\vscode-webhint\dist\src\server.js:1:1214
    at async t.Analyzer.validateTextDocument (c:\Users\jsadoski\.vscode\extensions\ms-edgedevtools.vscode-edge-devtools-2.0.0\node_modules\vscode-webhint\dist\src\server.js:1:1139)
    at async c:\Users\jsadoski\.vscode\extensions\ms-edgedevtools.vscode-edge-devtools-2.0.0\node_modules\vscode-webhint\dist\src\server.js:1:139563 {
  status: 'AnalyzeError'
}
[Info  - 9:36:08 AM] Connection to server got closed. Server will restart.
Error loading "hint" package from "c:\Repos\my-repo"
Trying to load shared version
Found hint at c:\Users\jsadoski\AppData\Roaming\Code\User\globalStorage\ms-edgedevtools.vscode-edge-devtools\node_modules\hint\dist\src\lib\index.js
c:\Users\jsadoski\AppData\Roaming\Code\User\globalStorage\ms-edgedevtools.vscode-edge-devtools\node_modules\hint\dist\src\lib\analyzer.js:151
                throw new types_1.AnalyzerError(e, error_status_1.AnalyzerErrorStatus.AnalyzeError);
                      ^

AnalyzerError: Cannot read properties of undefined (reading 'getLocation')
    at Analyzer.analyze (c:\Users\jsadoski\AppData\Roaming\Code\User\globalStorage\ms-edgedevtools.vscode-edge-devtools\node_modules\hint\dist\src\lib\analyzer.js:151:23)
    at runNextTicks (node:internal/process/task_queues:61:5)
    at processImmediate (node:internal/timers:437:9)
    at async c:\Users\jsadoski\.vscode\extensions\ms-edgedevtools.vscode-edge-devtools-2.0.0\node_modules\vscode-webhint\dist\src\server.js:1:1214
    at async t.Analyzer.validateTextDocument (c:\Users\jsadoski\.vscode\extensions\ms-edgedevtools.vscode-edge-devtools-2.0.0\node_modules\vscode-webhint\dist\src\server.js:1:1139)
    at async c:\Users\jsadoski\.vscode\extensions\ms-edgedevtools.vscode-edge-devtools-2.0.0\node_modules\vscode-webhint\dist\src\server.js:1:139563 {
  status: 'AnalyzeError'
}
[Info  - 9:36:11 AM] Connection to server got closed. Server will restart.
Error loading "hint" package from "c:\Repos\my-repo"
Trying to load shared version
Found hint at c:\Users\jsadoski\AppData\Roaming\Code\User\globalStorage\ms-edgedevtools.vscode-edge-devtools\node_modules\hint\dist\src\lib\index.js
c:\Users\jsadoski\AppData\Roaming\Code\User\globalStorage\ms-edgedevtools.vscode-edge-devtools\node_modules\hint\dist\src\lib\analyzer.js:151
                throw new types_1.AnalyzerError(e, error_status_1.AnalyzerErrorStatus.AnalyzeError);
                      ^

AnalyzerError: Cannot read properties of undefined (reading 'getLocation')
    at Analyzer.analyze (c:\Users\jsadoski\AppData\Roaming\Code\User\globalStorage\ms-edgedevtools.vscode-edge-devtools\node_modules\hint\dist\src\lib\analyzer.js:151:23)
    at runNextTicks (node:internal/process/task_queues:61:5)
    at processImmediate (node:internal/timers:437:9)
    at async c:\Users\jsadoski\.vscode\extensions\ms-edgedevtools.vscode-edge-devtools-2.0.0\node_modules\vscode-webhint\dist\src\server.js:1:1214
    at async t.Analyzer.validateTextDocument (c:\Users\jsadoski\.vscode\extensions\ms-edgedevtools.vscode-edge-devtools-2.0.0\node_modules\vscode-webhint\dist\src\server.js:1:1139)
    at async c:\Users\jsadoski\.vscode\extensions\ms-edgedevtools.vscode-edge-devtools-2.0.0\node_modules\vscode-webhint\dist\src\server.js:1:139563 {
  status: 'AnalyzeError'
}
[Info  - 9:36:15 AM] Connection to server got closed. Server will restart.
Error loading "hint" package from "c:\Repos\my-repo"
Trying to load shared version
Found hint at c:\Users\jsadoski\AppData\Roaming\Code\User\globalStorage\ms-edgedevtools.vscode-edge-devtools\node_modules\hint\dist\src\lib\index.js
c:\Users\jsadoski\AppData\Roaming\Code\User\globalStorage\ms-edgedevtools.vscode-edge-devtools\node_modules\hint\dist\src\lib\analyzer.js:151
                throw new types_1.AnalyzerError(e, error_status_1.AnalyzerErrorStatus.AnalyzeError);
                      ^

AnalyzerError: Cannot read properties of undefined (reading 'getLocation')
    at Analyzer.analyze (c:\Users\jsadoski\AppData\Roaming\Code\User\globalStorage\ms-edgedevtools.vscode-edge-devtools\node_modules\hint\dist\src\lib\analyzer.js:151:23)
    at runNextTicks (node:internal/process/task_queues:61:5)
    at processImmediate (node:internal/timers:437:9)
    at async c:\Users\jsadoski\.vscode\extensions\ms-edgedevtools.vscode-edge-devtools-2.0.0\node_modules\vscode-webhint\dist\src\server.js:1:1214
    at async t.Analyzer.validateTextDocument (c:\Users\jsadoski\.vscode\extensions\ms-edgedevtools.vscode-edge-devtools-2.0.0\node_modules\vscode-webhint\dist\src\server.js:1:1139)
    at async c:\Users\jsadoski\.vscode\extensions\ms-edgedevtools.vscode-edge-devtools-2.0.0\node_modules\vscode-webhint\dist\src\server.js:1:139563 {
  status: 'AnalyzeError'
}
[Error - 9:36:18 AM] Connection to server got closed. Server will not be restarted.

Here is a sample of my HTML:

Click to expand
{% load static %}
<!DOCTYPE html>
<html lang="en" class="perfect-scrollbar-off nav-open">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
    <meta name="theme-color" content="#000000" />
    <!--
      manifest.json provides metadata used when your web app is added to the
      homescreen on Android. See https://developers.google.com/web/fundamentals/engage-and-retain/web-app-manifest/
    -->
    <link rel="manifest" href="{% static 'manifest.json' %}" />
    <!-- <link rel="shortcut icon" href="{% static 'client/public/manifest.json' %}" />
    <link rel="apple-touch-icon" sizes="76x76" href="%PUBLIC_URL%/apple-icon.png" /> -->
    <!-- Fonts -->
    <link
      href="https://fonts.googleapis.com/css?family=Open+Sans:300,400,600,700"
      crossorigin="anonymous"
      integrity=""
      rel="stylesheet"
    />

    <link rel="stylesheet" type="text/css" href="{% static 'clinical-outcomes-yearly-reports.css' %}" />
    <title>Embed with other content</title>
  </head>
  <body>
    <noscript>You need to enable JavaScript to run this app. </noscript>
    <main>
      <iframe
        title="My iframe to other content"
        src="/fakesite"
      ></iframe>
    </main>
  </body>
</html>

Repro steps:

Open VSCode with the Microsoft Edge Tools enabled, then open this file.

Expected behavior:

MS Edge Tools server to not crash :)

Additional context:

jSadoski avatar May 27 '22 13:05 jSadoski

Thanks for the report @jSadoski! I think this is hitting the same underlying problem as this webhint bug and will need to be fixed by us: https://github.com/webhintio/hint/issues/5082#issuecomment-1136344296.

In that case the issue was due to the presence of zero-width spaces but in this case, it's due to the {% load static %} at the top of the file. Basically, when the doc is parsed statically as HTML (which webhint does to perform analysis), the template content causes the HTML parser to open the <body> tag early as it sees the template content as text. This leaves the <head> empty which breaks an assumption in hint-meta-charset-utf8. Basically, the resulting DOM looks like this:

<html lang="en" class="perfect-scrollbar-off nav-open"><head></head><body>{% load static %}

This is an artifact of how the static analysis is performed since under normal conditions such template tags would be removed/replaced by server-side logic before being sent to the browser. In both cases, I think this requires a fix to hint-meta-charset-utf8 in our webhint dependency since that's where the error is originating from.

antross avatar May 27 '22 18:05 antross

@vidorteg thinking about this some more, I suspect fixing the assumption in hint-meta-charset-utf8 will resolve the error, but still result in a false-positive because the meta tags get pushed to the <body> instead of the <head> during static analysis.

We may need to consider some level of pre-processing to augment/remove such template tags (at least when they occur between tags before <body>) to help the resulting DOM more closely resemble what would be handled by the browser after server-side processing. These particular tags appear to be from Django (https://docs.djangoproject.com/en/4.0/ref/templates/builtins/#static-1), but we should take the time to account for variations in template syntax from other popular frameworks as well.

antross avatar May 27 '22 18:05 antross

The issue Tony linked to is now closed. Closing this one.

captainbrosset avatar Mar 27 '23 08:03 captainbrosset