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 launching custom tasks (cannot read property 'cwd' of undefined) #9743

Closed
tsmaeder opened this issue Jul 15, 2021 · 5 comments · Fixed by #9747
Closed

Error launching custom tasks (cannot read property 'cwd' of undefined) #9743

tsmaeder opened this issue Jul 15, 2021 · 5 comments · Fixed by #9747
Labels
bug bugs found in the application tasks issues related to the task system vscode issues related to VSCode compatibility

Comments

@tsmaeder
Copy link
Contributor

Bug Description:

When launching tasks with custom executions (for example from the gradle VS Code extensions), we get errors saying

TypeError: Cannot read property 'cwd' of undefined

I was able to trace the problem to this PR:

https://github.com/eclipse-theia/theia/pull/9695/files#diff-6268a7212c6dfa3764fd2c66d3acfd23d8920a9264a28c1ec4a72210121bf96cR199

The problem is that taskConfig.options is not mandatory.

Steps to Reproduce:

  1. Install vscode-java 0.80.0
  2. Open a Java project
  3. Observe: vscode-java shows a rotating progress indicator at the right bottom corner of the window
  4. Click on the progress indicator
  5. A popup appears saying "Error launching task 'Java Build Status': Cannot read property 'cwd' of undefined"

Additional Information

  • Operating System: Window
  • Theia Version: master
@vince-fugnitto vince-fugnitto added bug bugs found in the application tasks issues related to the task system vscode issues related to VSCode compatibility labels Jul 15, 2021
@tsmaeder
Copy link
Contributor Author

tsmaeder commented Jul 15, 2021

I guess one of the reasons this problem appeared is that we don't have proper typing of the options field in TaskDto, TaskConfiguration, etc. The problem is that those types have a "catch-all" field like

TaskDto {
...
 [key: string]: any;

We really should add all known fields with proper typing in any types where they apply. Generally, I would refactor those types to have a fixed set of properties like so:

TaskDto {
   label: string,
   ...
   extraProperties: {
       [key: string]: any;
   }
} 

This way, we would notice if we're adding a property somewhere but leave it out in related types.

@tsmaeder
Copy link
Contributor Author

@kenneth-marut-work do you have time to fix this in the short term? You're probably most familiar with that particular code.

@kenneth-marut-work
Copy link
Contributor

@kenneth-marut-work do you have time to fix this in the short term? You're probably most familiar with that particular code.

Sure I'll try to get to it today 👍

@colin-grant-work
Copy link
Contributor

I guess one of the reasons this problem appeared is that we don't have proper typing of the options field in TaskDto, TaskConfiguration, etc. The problem is that those types have a "catch-all" field like

TaskDto {
...
 [key: string]: any;

@tsmaeder, I agree with your suggestion. We have the no-explicit-any lint rule, but we're a bit cavalier about disabling it. We really ought to use unknown more often, so that Typescript forces (or at least encourages) us to actually check the type before using it.

@alvsan09
Copy link
Contributor

This can also be reproduced using the vscode sample:
task-provider-sample

Run the task: Command Palette -> Tasks: run Task -> custombuildscript: 32 watch incremental

kenneth-marut-work added a commit to kenneth-marut-work/theia that referenced this issue Jul 15, 2021
Fixes eclipse-theia#9743 by improving check for taskConfig.options.cwd from eclipse-theia#9695.
Also ensures that lastCwd field on terminal-widget is never undefined
as to ensure get cwd() will always return a URI.

Signed-off-by: Kenneth Marut <[email protected]>
tsmaeder pushed a commit that referenced this issue Jul 16, 2021
Fixes #9743 by improving check for taskConfig.options.cwd from #9695.
Also ensures that lastCwd field on terminal-widget is never undefined
as to ensure get cwd() will always return a URI.

Signed-off-by: Kenneth Marut <[email protected]>
dna2github pushed a commit to dna2fork/theia that referenced this issue Aug 25, 2021
Fixes eclipse-theia#9743 by improving check for taskConfig.options.cwd from eclipse-theia#9695.
Also ensures that lastCwd field on terminal-widget is never undefined
as to ensure get cwd() will always return a URI.

Signed-off-by: Kenneth Marut <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug bugs found in the application tasks issues related to the task system vscode issues related to VSCode compatibility
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants