Attempting to compile from VSCode extension a file that hasn't been saved results in an exception for the VSCode extension
- Dominant language
- Bicep
- Stars
- 3.6k
- Forks
- 830
- Avg merge
- 1d 21m
- Merged PRs (30d)
- 79
Description
**Bicep version**
run `bicep --version` via the Bicep CLI, `az bicep version` via the AZ CLI or via VS code by navigating to the extensions tab and searching for Bicep
https://user-images.githubusercontent.com/9611108/219785099-6ff1c794-5e4d-480d-bca2-dbab2c27125a.png
**Describe the bug**
A clear and concise description of what the bug is vs what you expected to happen
When you attempt to use the VSCode extension context menu to compile a file that hasn't been yet saved, the VSCode extension throws an unhandled exception.

**To Reproduce**
Steps to reproduce the behavior:
1. Open VSCode > Install latest Bicep extension
1. Go to File > New File... > Select Text File to create an untitled file


1. Select Bicep as a language

1. Paste the following snippet:
```bicep
resource t 'Microsoft.ScVmm/vmmServers@2020-06-05-preview' = {
name: 'vmmServerName'
location: 'location'
properties: {
fqdn: 'boo.foo.com'
}
extendedLocation: {
name: 'extendedLocationName'
type: 'Microsoft.HyperVManager/locations'
}
}
```
1. Right click and select "Build ARM Template"

## Expected Behavior
The VSCode extension should ask the user to save the file before trying to compile and/or handle the situation accordingly. In any case it should not throw an unhandled exception.
A potential sufficient solution would be to disable the contextual 'Build ARM Template' trigger when the file hasn't been saved.
## Actual Behavior
An unhandled exception is thrown by the extension as seen in the image above (in the description)
Contributor guide
Research direction
Reproduce the issue in the VSCode extension by opening an unsaved untitled file, selecting Bicep, and choosing “Build ARM Template” from the context menu. Trace the command handling from that menu action and make the unsaved-file case avoid an unhandled exception, either by requesting a save or disabling the command; verify the behavior manually.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- vscode
- Domain
- developer-experience, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100