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

Request 'setStorageValue' failed on closing file without workspace when SQLTools extension is install #8963

Closed
odeliat opened this issue Jan 18, 2021 · 4 comments · Fixed by #9137
Labels
🤔 needs more info issues that require more info from the author vscode issues related to VSCode compatibility

Comments

@odeliat
Copy link
Contributor

odeliat commented Jan 18, 2021

Bug Description:

When I install SQLTools extension and close file without workspace I get this error: (attached screen video)

root ERROR [hosted-plugin: 12752] Promise rejection not handled in one second: Error: Request setStorageValue failed with message: Cannot save data: no opened workspace , reason: Error: Request setStorageValue failed with message: Cannot save data: no opened workspace
root ERROR [hosted-plugin: 12752] With stack trace: Error: Request 'setStorageValue' failed
    at Proxy.<anonymous> (http://localhost:3000/bundle.js:143539:33)
    at StorageMainImpl.push.../../packages/plugin-ext/lib/main/browser/plugin-storage.js.StorageMainImpl.$set (http://localhost:3000/56.bundle.js:9109:34)
    at RPCProtocolImpl.push.../../packages/plugin-ext/lib/common/rpc-protocol.js.RPCProtocolImpl.doInvokeHandler (http://localhost:3000/39.bundle.js:1207:23)
    at RPCProtocolImpl.push.../../packages/plugin-ext/lib/common/rpc-protocol.js.RPCProtocolImpl.invokeHandler (http://localhost:3000/39.bundle.js:1192:41)
    at RPCProtocolImpl.push.../../packages/plugin-ext/lib/common/rpc-protocol.js.RPCProtocolImpl.receiveRequest (http://localhost:3000/39.bundle.js:1156:31)
    at RPCProtocolImpl.push.../../packages/plugin-ext/lib/common/rpc-protocol.js.RPCProtocolImpl.receiveOneMessage (http://localhost:3000/39.bundle.js:1125:22)
    at http://localhost:3000/39.bundle.js:1017:109
    at http://localhost:3000/39.bundle.js:1232:17
    at http://localhost:3000/bundle.js:141091:33
    at CallbackList.../../packages/core/lib/common/event.js.CallbackList.invoke (http://localhost:3000/bundle.js:141106:39)

The error is in file packages\plugin-ext\src\main\node\plugins-key-value-storage.ts:59 (set method)

sql-tools.mp4

I created a new extension with the use of workspaceState and got the same error but did get the string:

context.workspaceState.update("obj", "hi");
const msg = context.workspaceState.get("obj");
vscode.window.showInformationMessage(msg);

TheSQLTools also use the same code

Steps to Reproduce:

  1. Run the server locally.
  2. Install the SQLTools.
  3. Make sure there is no open workspace.
  4. Open a random file.
  5. Close that file.
  6. Get the error on the server side.

Additional Information

  • Operating System: Local
  • Theia Version: master
@vince-fugnitto
Copy link
Member

@odeliat based on the condition, are you certain it's an actual issue? A workspace must be opened before you can set the the storage:

async set(key: string, value: KeysToAnyValues, kind: PluginStorageKind): Promise<boolean> {
const dataPath = await this.getDataPath(kind);
if (!dataPath) {
throw new Error('Cannot save data: no opened workspace');
}
const data = await this.readFromFile(dataPath);

The same is true for workspaceState, based on the documentation, it applies to only opened workspaces:

image

@vince-fugnitto vince-fugnitto added 🤔 needs more info issues that require more info from the author vscode issues related to VSCode compatibility labels Jan 18, 2021
@odeliat
Copy link
Contributor Author

odeliat commented Jan 19, 2021

@vince-fugnitto This issue happens in Theia but not in vscode.
In vscode I am able to open and save files without a workspace. I tried the extension in vscode and didn't get the error.
In Theia I am also able to do that (system files) but I get this error.

The set method is activate but the kind parameter is empty and that is why we get the error thrown in line 59.

@vince-fugnitto
Copy link
Member

@odeliat I'm not sure what you're expecting, by design the storage only works when a workspace is present:

async set(key: string, value: KeysToAnyValues, kind: PluginStorageKind): Promise<boolean> {
const dataPath = await this.getDataPath(kind);
if (!dataPath) {
throw new Error('Cannot save data: no opened workspace');
}

private async getDataPath(kind: PluginStorageKind): Promise<string | undefined> {
if (!kind) {
return this.deferredGlobalDataPath.promise;
}
const storagePath = await this.pluginPathsService.getHostStoragePath(kind.workspace, kind.roots);
return storagePath ? path.join(storagePath, 'workspace-state.json') : undefined;
}

async getHostStoragePath(workspaceUri: string | undefined, rootUris: string[]): Promise<string | undefined> {
const parentStorageDir = await this.getWorkspaceStorageDirPath();
if (!parentStorageDir) {
throw new Error('Unable to get parent storage directory');
}
if (!workspaceUri) {
return undefined;
}

When no workspace is present, the path is undefined meaning that storage is disabled and should not occur.

If you're looking to set storage independent of the workspace, then globalState should be used instead of workspaceState:

image

Note: I cannot tell what vscode-sqltools is doing since their extension code is obfuscated.

@danarad05
Copy link
Contributor

@odeliat @vince-fugnitto @amiramw
created small PR for this issue. You can call it a minor validation for case where extension sends false indication (it sends argument isGlobal = false - when workspace exists and when it doesn't).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤔 needs more info issues that require more info from the author vscode issues related to VSCode compatibility
Projects
None yet
3 participants