Azure / Azure/bicep

Attempting to compile from VSCode extension a file that hasn't been saved results in an exception for the VSCode extension

Open
#9,867 0 comments 0 reactions 0 assignees View on GitHub
investigate
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.
![image](https://user-images.githubusercontent.com/9611108/219788297-c5a8c059-4cf3-45c3-bdff-d5ff0b1588a8.png)

**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
![image](https://user-images.githubusercontent.com/9611108/219788515-6e2683f9-5119-4fb8-b2cc-4ab5f527db0c.png)
![image](https://user-images.githubusercontent.com/9611108/219788654-8d3b18fe-9abe-4d5d-8d18-bf737117d8e1.png)
1. Select Bicep as a language
![image](https://user-images.githubusercontent.com/9611108/219788779-ae549701-1a21-4ec9-8f9b-7803fbcebd5d.png)
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"
![image](https://user-images.githubusercontent.com/9611108/219788945-84f7429b-684a-4a87-bae9-834a119abbca.png)

## 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

Open the contributing 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.