Skip to content

File name error causes Volar to crash #159

@chizukicn

Description

@chizukicn

Describe the bug:

When I reference the @antv/g2 package in the vue file, volar will report an error and crash directly.

image

If I do not reference this package before opening vscode, volar will not crash if I reference this package after opening vscode.

If this package is referenced before open vscode, volar will crash directly.

So I think this should be a problem triggered by volar during initialization.

When I use vscode extension code debugging, this error is displayed as

image

When I added a try-catch where this function was called, volar no longer crashed.

// @volar/typescript/lib/protocol/createSys -> function directoryExists
    function directoryExists(dirName) {
        const oldDirName = dirName;
        dirName = resolvePath(dirName);
        const dir = getDir(dirName);
        if (dir.exists === undefined) {
            dir.exists = false;
            try{
                const result = env.fs?.stat(env.typescript.fileNameToUri(dirName));
                if (typeof result === 'object' && 'then' in result) {
                    const promise = result;
                    promises.add(promise);
                    result.then(result => {
                        promises.delete(promise);
                        dir.exists = result?.type === 2;
                        if (dir.exists) {
                            version++;
                        }
                    });
                }
                else {
                    dir.exists = result?.type === 2;
                }    
            }catch {

            }
        }
        return dir.exists;
    }

ps: This problem only occurs in volar versions 2.0.7 and above, and will not be triggered in volar 2.0.6

VSCode version: 1.87.2 (Universal)
VSCode Extension version: 2.0.8
Typescript version: 5.4.2
NodeJS version: 18.17.1
Operating System: macOS 14.4.1 (arm64 Apple silicon)
Reproduction Repository: https://github.com/chizukicn/volar_reproduction

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions