microsoft / vscode-docker

Docker Extension for Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-docker
Other
1.22k stars 518 forks source link

Path Argument Error When Adding Flutter Support to VS Code Docker Extension #4357

Closed hs-dev1 closed 2 months ago

hs-dev1 commented 3 months ago

I've been working on adding support for Flutter projects in the ms-azuretools.vscode-docker extension. This involves generating Dockerfiles for Flutter projects. However, I've encountered an error related to the path argument being undefined. The specific error message is: "Error: The 'path' argument must be of type string. Received undefined."

I am trying to add the path when generating the Dockerfile into the project for Flutter, but it's not working and throws the error mentioned above.

Here is the function where I add the path when generating the Dockerfile. If you need the code, please let me know. ` private async getInputPath(wizardContext: TWizardContext): Promise { const config = vscode.workspace.getConfiguration('docker'); const settingsTemplatesPath = config.get<string | undefined>('scaffolding.templatePath', undefined); const defaultTemplatesPath = path.join(ext.context.asAbsolutePath('resources'), 'templates');

    console.log('Workspace Folder:', wizardContext.workspaceFolder);
    console.log('Dockerfile Directory:', wizardContext.dockerfileDirectory);
    ///TODO: for flutter [dockerfileDirectory] is undefined need to check that

    let subPath: string;
    switch (wizardContext.platform) {
        case 'Node.js':
            subPath = path.join('node', `${this.fileType}.template`);
            break;
        case 'Flutter':
            subPath = path.join('flutter', `${this.fileType}.template`);
            break;
        case 'Python: General':
            subPath = path.join('python', `${this.fileType}.template`);
            break;
        // Additional cases...
        default:
            throw new Error(`Unknown platform '${wizardContext.platform}'`);
    }

    // Validate paths before usage
    console.log('Settings Templates Path:', settingsTemplatesPath);
    console.log('Default Templates Path:', defaultTemplatesPath);
    console.log('SubPath:', subPath);

    if (!settingsTemplatesPath && !defaultTemplatesPath) {
        throw new Error('Both settingsTemplatesPath and defaultTemplatesPath are undefined.');
    }

    // Use valid paths
    return (settingsTemplatesPath && await this.scanUpwardForFile(path.join(settingsTemplatesPath, subPath))) ||
        await this.scanUpwardForFile(path.join(defaultTemplatesPath, subPath));
}

`

but if I select any other option it generates Dockerfile normally.

hussnain-2015371 commented 3 months ago

Kindly assist on this @bwateratmsft , @chrisdias , @StephenWeatherford , @ravipal

dbreshears commented 3 months ago

@hussnain-2015371 , can you share the error message or call stack of where you hit this. Or please share out a branch or repo for your code. In a simple test I was able to make this work

hs-dev1 commented 3 months ago

@hussnain-2015371 , can you share the error message or call stack of where you hit this. Or please share out a branch or repo for your code. In a simple test I was able to make this work

here's branch: https://github.com/hs-dev1/vscode-docker/tree/vscode-docker-flutter

dbreshears commented 3 months ago

@hussnain-2015371, after line 18 in https://github.com/hs-dev1/vscode-docker/blob/vscode-docker-flutter/src/scaffolding/wizard/flutter/FlutterGatherInformationStep.ts you need to call

await super.prompt(wizardContext);

the base GatherInformationStep sets the wizardContext.dockerfileDirectory

AzCode-Bot commented 2 months ago

This issue has been closed automatically because it needs more information and has not had recent activity. See also our issue reporting guidelines.

Happy Coding!