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

Fix "Converting circular structure to JSON" Error #5121

Closed
wants to merge 1 commit into from

Conversation

vinokurig
Copy link
Contributor

Fix "Converting circular structure to JSON" Error that causes when launching VsCode GitHub-Pull-Request-Plugin.
Is needed for eclipse-che/che#11867

try {
return JSON.parse(JSON.stringify(value));
} catch (e) {
return;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VS Code translates circular ref to null

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed to return undefined

@akosyakov
Copy link
Member

@vinokurig How can one verify it? Is it about: #4975?

@vinokurig
Copy link
Contributor Author

@akosyakov looks like it should solve the issue, I'll check it

@vinokurig vinokurig force-pushed the fixRpcError branch 2 times, most recently from 1b81e92 to a5e02f0 Compare May 13, 2019 11:36
Signed-off-by: Igor Vinokur <ivinokur@redhat.com>
@vinokurig
Copy link
Contributor Author

vinokurig commented May 13, 2019

@akosyakov I've launched the microclimate-vscode plugin (#4975) and the issue was not reproduced:
screenshot-localhost-3030-2019 05 13-14-40-47

@akosyakov
Copy link
Member

akosyakov commented May 13, 2019

Why cannot we do it the same like VS Code do: https://github.com/microsoft/vscode/blob/0fde6619172c9f04c41f2e816479e432cc974b8b/src/vs/workbench/services/extensions/common/rpcProtocol.ts#L22-L28

Without caches and serializing/deserializing all objects (which look expensive)? It seems to be more performant, compatible with VS Code and simple. Plus apply it in all places, not only for replyOk?

@vinokurig
Copy link
Contributor Author

@akosyakov The plugin didn't work with that solution. Probably VsCode uses another replacers.

return undefined;
}
}
cache.push(value);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does it ever reach this code?

@akosyakov
Copy link
Member

@vinokurig Don't you think it is bad to serilaize and parse each property of each object? I don't think this solution is in the right direction. VS Code replacer only handles URI i wonder what we do differently that we have to go for such expensive strategies.

@benoitf
Copy link
Contributor

benoitf commented May 15, 2019

I also agree that the fix should be better than what is being done. It's too costly

Copy link
Contributor

@benoitf benoitf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

somehow the fix should avoid to unwrap/wrap each element

ariel-bentu pushed a commit to ariel-bentu/theia that referenced this pull request May 18, 2019
…\n Signed-off-by: Ariel Bentolila <ariel.bentolila@sap.com>
ariel-bentu pushed a commit to ariel-bentu/theia that referenced this pull request May 18, 2019
…\n Signed-off-by: Ariel Bentolila <ariel.bentolila@sap.com>
@ariel-bentu ariel-bentu mentioned this pull request May 18, 2019
@ariel-bentu
Copy link

Hi,
as you can see I proposed a PR to fix this, I was circling the same problem and then I saw this thread.
Please consider this one. It solved my issue, maybe will solve also the ones mentioned in this thread?
Thanks

#5185

ariel-bentu pushed a commit to ariel-bentu/theia that referenced this pull request May 18, 2019
…\n Signed-off-by: Ariel Bentolila <ariel.bentolila@sap.com>

Signed-off-by: Ariel Bentolila <ariel.bentolila@sap.com>
@ariel-bentu
Copy link

After some more investigation and the latest PR I made #5196, I think I figured out what is fundamentally wrong in tree views for plugin/vscde-extensions in Theia, which exposes this issue in many cases:

The way the tree view is implemented (TreeViewsExt, TreeViewItem, tree-view-main.tsx etc) is that the server-side object representing a TreeItem is moved (via json-rpc) from server to client upon getChildren call (specifically the original object is placed under metadata defined in TreeViewItem.
Then, upon context-menu, or inline-action-icons the relevant command is triggered from the browser via rpc passing back the object stored in the member metadata, to the command.

This back and forth move of the actual object of the tree-item is the source of some major problems:

  1. these objects tend to have circular-references, thus pose a challenge to serialize them (fixed in my PR)
  2. These objects could be large, and serve no purpose on the client other than to be sent back in case of menu/action-icon clicked
  1. When they are deserialized back to object on the server they loose all the functions and private data they had before sent to the browser - thus break a lot of existing vscode-extensions.

The right way to do it (and I guess vscode do exactly that), is to avoid sending these objects to the browser. Upon menu or click on action icon, send to the server a call indicating that the menu was triggered, or the action-icon was clicked. the actual for the command behind the menu or action icon would be called from the server-side, passing the original item's object (with all its functions and private data).

What do you think?

I believe this would solve #4975 as well.

@benoitf
Copy link
Contributor

benoitf commented May 20, 2019

@ariel-bentu 👍
it would be definitely a better fix if no circular JSON is sent (and that we don't send large data over the network for nothing)

@ariel-bentu
Copy link

I updated PR #5196 to do that. please help to promote its acceptance.

@vinokurig
Copy link
Contributor Author

@vinokurig vinokurig reopened this Jul 4, 2019
@vinokurig
Copy link
Contributor Author

Will fix in another way

@vinokurig vinokurig closed this Jul 5, 2019
@vinokurig vinokurig deleted the fixRpcError branch August 5, 2019 11:16
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

Successfully merging this pull request may close these issues.

5 participants