Repository: vscode
Issue: Connecting to Live Share session causes NPE in workspace trust subsystem
Labels: bug,workspace-trust

<!-- ⚠️⚠️ Do Not Delete This! bug_report_template ⚠️⚠️ -->
<!-- Please read our Rules of Conduct: https://opensource.microsoft.com/codeofconduct/ -->
<!-- 🕮 Read our guide about submitting issues: https://github.com/microsoft/vscode/wiki/Submitting-Bugs-and-Suggestions -->
<!-- 🔎 Search existing issues to avoid creating duplicates. -->
<!-- 🧪 Test using the latest Insiders build to see if your issue has already been fixed: https://code.visualstudio.com/insiders/ -->
<!-- 💡 Instead of creating your report here, use 'Report Issue' from the 'Help' menu in VS Code to pre-fill useful information. -->
<!-- 🔧 Launch with `code --disable-extensions` to check. -->
Does this issue occur when all extensions are disabled?: Yes (all except Live Share)

<!-- 🪓 If you answered No above, use 'Help: Start Extension Bisect' from Command Palette to try to identify the cause. -->
<!-- 📣 Issues caused by an extension need to be reported directly to the extension publisher. The 'Help > Report Issue' dialog can assist with this. -->
- Version: 1.85.0
- Commit: af28b32d7e553898b2a91af498b1fb666fdebe0c
- Date: 2023-12-06T17:43:36.790Z (6 days ago)
- Browser: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36
- Live Share: v1.0.5900

Steps to Reproduce:

1. Live Share: Sign In
2. Try to connect to a Live Share session (click Join, sign in, then paste the invitation link)
3. Window reloads, starts opening the live share workspace, presents a workspace trust modal, asking me to trust `/tmp/vsliveshare-workspace-tmp-<stuff>/Visual Studio Live Share (Workspace)`. Click "Yes, I trust the authors". VS Code logs an exception and stops opening the workspace.  <-- this is where the bug is, I'd expect it to open the workspace and connect
4. Use Developer: Reload Window
5. After reloading, we start in Restricted Mode, with a banner across the top "Restricted Mode is intended for safe code browsing...". Click Manage, then Trust. This time, no exception.
6. Reload one more time, and now we're able to connect.

Here is the exception:
```
ERR Cannot read properties of undefined (reading 'scheme'): TypeError: Cannot read properties of undefined (reading 'scheme')
    at h.P (.../stable-af28b32d7e553898b2a91af498b1fb666fdebe0c/static/out/vs/workbench/workbench.web.main.js:2605:167197)
    at .../stable-af28b32d7e553898b2a91af498b1fb666fdebe0c/static/out/vs/workbench/workbench.web.main.js:2605:171789
    at Array.map (<anonymous>)
    at h.setUrisTrust (.../stable-af28b32d7e553898b2a91af498b1fb666fdebe0c/static/out/vs/workbench/workbench.web.main.js:2605:171777)
    at h.setWorkspaceTrust (.../stable-af28b32d7e553898b2a91af498b1fb666fdebe0c/static/out/vs/workbench/workbench.web.main.js:2605:171570)
    at m.completeWorkspaceTrustRequest (.../stable-af28b32d7e553898b2a91af498b1fb666fdebe0c/static/out/vs/workbench/workbench.web.main.js:2605:173655)
    at Object.run (.../stable-af28b32d7e553898b2a91af498b1fb666fdebe0c/static/out/vs/workbench/workbench.web.main.js:2690:68778)
    at c.f (.../stable-af28b32d7e553898b2a91af498b1fb666fdebe0c/static/out/vs/workbench/workbench.web.main.js:633:42862)
    at c.prompt (.../stable-af28b32d7e553898b2a91af498b1fb666fdebe0c/static/out/vs/workbench/workbench.web.main.js:766:23881)
```

It looks like one of the `uris` here is `undefined`: 

https://github.com/microsoft/vscode/blob/af28b32d7e553898b2a91af498b1fb666fdebe0c/src/vs/workbench/services/workspaces/common/workspaceTrust.ts#L620

Maybe this runs too early or something, before the folders in the workspace are fully initialized?

I feel like I've seen other cases where I need to try multiple times to trust a workspace if I click it too quickly, but this is the most reproducible. All you need to do is, in the window where you're hosting the Live Share collaboration session, stop it and start a new one - this will get you a fresh (untrusted) workspace for the collaborator that's joining. This makes it pretty easy to test.