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

[error] TypeError: Cannot read properties of undefined (reading 'paths') #24

Open
DanieleCremoniniOwkin opened this issue May 31, 2023 · 13 comments

Comments

@DanieleCremoniniOwkin
Copy link

Hi,

I have:

Visual Studio Code

  • Version: 1.78.2
  • Commit: b3e4e68a0bc097f0ae7907b217c1119af9e03435
  • Date: 2023-05-10T14:44:45.204Z (2 wks ago)
  • Electron: 22.5.2
  • Chromium: 108.0.5359.215
  • Node.js: 16.17.1
  • V8: 10.8.168.25-electron.0
  • OS: Darwin x64 21.6.0
  • Sandboxed: Yes

ZenWave Karate IDE v1.3.4
ZenWave KarateIDE Classpath Jar v1.4.0
Karate Jar: karate-1.4.0.jar

Procedure
In the explorer, I right click a yaml file, then I click Karate IDE Generate Karate Test

Results
While with the petstore.yaml, the plugin works, with a api.yaml file created by me I get the error message below:

2023-05-31 16:20:41.076 [error] TypeError: Cannot read properties of undefined (reading 'paths')
	at t.getOperationsFor (/Users/dcremonini/.vscode/extensions/karateide.karate-ide-1.3.4/dist/extension.js:2:257374)
	at /Users/dcremonini/.vscode/extensions/karateide.karate-ide-1.3.4/dist/extension.js:2:252610
	at Generator.next (<anonymous>)
	at a (/Users/dcremonini/.vscode/extensions/karateide.karate-ide-1.3.4/dist/extension.js:2:251678) karateIDE.generators.openapi.test {"value":"KarateIDE.karate-ide","c":"karateide.karate-ide"}

Additional information

  • There aren't any similar bugs.
  • A comparison of the structure of the petstore.yaml and of api.yaml doesn't ring any bell.
  • I reinstalled the plugins a few times.
  • I can't share the original file but I'm willing to work on it to nail down the problem.
  • If I rename karate-1.4.0.jar to karate.jar has no effect.
  • In .vscode/settings.json I have:
{
    "karateIDE.karateCli.karateEnv": ""
}
@ivangsa
Copy link
Member

ivangsa commented Jun 1, 2023

Hi @DanieleCremoniniOwkin

thanks for take the time to report this,

it seams that its not finding the petstore.yaml file for parsing...

I will request some help from OSX users to see if this is related to the OS...

Does this fail with every yaml file or just this petstore.yaml ?

@DanieleCremoniniOwkin
Copy link
Author

Hi @ivangsa ,

this is not what I meant.
If I use the plugin with petstore.yaml, it works.
If I use it with api.yaml it doesn't work.

If you can redirect me to some "how to contribute" page, I can set up the project and give a try on my own.
Thank you
Daniele

@ivangsa
Copy link
Member

ivangsa commented Jun 1, 2023

Starting Karate-ide in debug mode is very easy.

Two steps:

  • npm run watch
  • Press F5 or "Run Extension" from the debugger pannel

This will start a new window where you can 'use' the plugin

Place a break point arround src\generators\openapi\OpenAPIGenerator.ts line 21

@DanieleCremoniniOwkin
Copy link
Author

I had a debugging session with Visual Studio Code.
Steps to make the debugger work:

  • from the terminal
    npm install
  • then
    npm run watch
  • I enabled the Debug attachment in Visual Studio Code (tried both Auto and always)
  • I opened the file OpenApiGenerator.ts and hit F5. The debugger kicks in.

Error 1

When I start the debug session (but haven't asked yet to generate the test), I get this error:

vscode.workspace.workspaceFolders[0]

Uncaught TypeError TypeError: Cannot read properties of undefined (reading '0')
    at eval (repl:1:34)

and this is because

vscode.workspace.workspaceFolders is undefined

In FilesManager.loadfiles, I check the condition as below:

        if (moduleRootFolders.length === 0) {
            if (vscode.workspace.workspaceFolders !== undefined) {
                moduleRootFolders.push(vscode.workspace.workspaceFolders[0].uri);
            }
        }

and the error message went away.

Error 2

The debugger stop on some lines but to all of them. I think it stops when initializing the extension but it doesn't when I try to generate the tests.

  1. If I right click on the petstore.yaml file, a combo list appears and I can choose one or more entrypoint to generate tests for. I choose a target directory and I can successfully generate the tests for PetApi.

The breakpoint at the line 21 of
export async function generateKarateTestFromOpenAPI(file: vscode.Uri)
is not honoured.
I also put a breakpoint at the beginning of
export function getOperationsFor(api)
and it's also not honoured.

  1. If I right click on the api.yaml file, the combo list doesn't even appear. I put dozens of breakpoint here and there without seeing the process stop where I wanted to. The same about the breakpoint in the line 21 is true.

Do you have any clue?
Thank you
Daniele

@ivangsa
Copy link
Member

ivangsa commented Jun 2, 2023

(you don't need to attach the debuggeer to npm run watch)

Error 1: load files should work only after opening a workspace, but shouldn't throw an error (that is a bug). On the debugged window open a workspace to work with.

Error 2: not sure why the debugger doesn't stop, and I know it's uggly but use console.log to make sure it goes inside getOperationsFor for one file but not the other..

@DanieleCremoniniOwkin
Copy link
Author

Error 1: I found that it's a normal behaviour of Visual Studio Code. I will investigate later to confirm if a patch would be benefical.

Error 2: the debugger actually works, but not all the time. console.log doesn't work at all. I tried to rebuild the dist directory from scratch.

Other thoughts
It looks like the search operation is meant for Java projects. In the code there are some:

  • src/test/resources
  • /src/test//*.feature

that lock contraint the way the file system has to be shaped.
The project I'm working on, is trying to be language agnostic. Other than the karate jar and a working JDK, I don't think that Karate API needs the Maven standard file system structure, does it?
Maybe if I enforce a certain file system structure, it will work?

@ivangsa
Copy link
Member

ivangsa commented Jun 5, 2023

It looks like the search operation is meant for Java projects. In the code there are some:
src/test/resources

This is configurable through settings but I expect most users will automate through maven tests but it's configurable

Error 2: the debugger actually works, but not all the time. console.log doesn't work at all

Make sure you run npm run watch and it finishes ok, sometime it doesnt' compile and I don't realize because is on a hidden terminal

@DanieleCremoniniOwkin
Copy link
Author

npm run watch is running continuously without any appearing problem.

Anyway, if I change the

vscode.window.showInformationMessage(`Karate Test features generated in: ${vscode.workspace.asRelativePath(apisFolder, false)}`);
to
vscode.window.showInformationMessage(`CCC Karate Test features generated in: ${vscode.workspace.asRelativePath(apisFolder, false)}`);

the CCC Karate Test features generated string is not taken into account while debugging (see image below):

O Karate Test features generated in outder

Please note that:

  • The CCC Karate Test features generated is reflected in extension.js in the dist directory
  • I tried to change some settings in tsconfig.json.
  • I cleaned node_modules, and dist directories.

Do you have any trick?

@ivangsa
Copy link
Member

ivangsa commented Jun 5, 2023

I think the vscode window where you are testing (where you see Karate Test features generated in...) is not the window started or attached by the debugger...

@DanieleCremoniniOwkin
Copy link
Author

DanieleCremoniniOwkin commented Jun 5, 2023

Thank you, eventually I can make it work.

The key is to start the debugging from the windows that has [Extension Development Host] in the title as in the image below:
Pasted Graphic 1

  • If I do this, the debugger stops and works correctly in extension.ts and in OpenApiGenerator.ts.
  • If I lunch the KarateIDE: Generate Karate Tests task from the VSC instance that has not [Extension Development Host] in its title, the debugger stops in extension.ts but it doesn't in OpenApiGenerator.ts.

Now I can focus on the bug. I'll keep you informed.

@DanieleCremoniniOwkin
Copy link
Author

Hi @ivangsa, I want to add some tests but the project doesn't have any boilerplate to run them.
Do you have something ready to add to the project?

@ivangsa
Copy link
Member

ivangsa commented Jun 9, 2023

hmm I'm afraid "tests" are some technical debt the project has.. but go ahead an propose something..

@DanieleCremoniniOwkin
Copy link
Author

Then I'll try to submit a first merge request with that infrastructure.
Let's keep this issue open for the moment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants