Repository navigation
Fix/powershell snippet fallback - #11
Conversation
The Microsoft DevX snippet API currently returns HTTP 500 for all PowerShell snippet generation requests, causing PowerShell code snippets to never render in the extension (fixes merill#8). This adds a local fallback that generates idiomatic PowerShell snippets using Invoke-MgGraphRequest when the DevX API fails: - Generates Import-Module + Connect-MgGraph boilerplate - Formats JSON request bodies as PowerShell hashtable literals - Handles nested objects, arrays, booleans, nulls, and numbers - Applies to both API error responses and network failures - Other languages continue using the DevX API as before Also fixes a minor bug: response.text() was not awaited on the success path (line 47), which could cause issues with logging. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Code Review
This pull request increments the project version to 1.0.6 and introduces a local fallback mechanism for generating PowerShell snippets in src/common/client.js when the DevX API is unavailable. The review feedback identifies several opportunities to improve the robustness of the generated PowerShell code, including quoting hashtable keys to support OData attributes, escaping special characters in strings to prevent unintended interpolation, and ensuring multi-line raw bodies are correctly commented out in fallback scenarios.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
@jorgeasaurus Tx a lot for the PR. I've already merged it. Are you making any new updates? |
|
You're welcome. No other changes at this time. |
|
Awesome tx. I'm making some other updates too to improve experience. Tx a lot for the Firefox PR too. I'll test it and include it in the list of supported browsers. |
Fix: PowerShell code snippets not appearing
Hi @merill 👋
Fixes #8
Problem
PowerShell code snippets fail to render in the Graph X-Ray DevTools panel. Other languages (C#, Python, Go, JavaScript, Java) work correctly.
Root cause: Microsoft's DevX snippet API (
devxapi-func-prod-eastus.azurewebsites.net) returns HTTP 500 for all PowerShell snippet generation requests. This is a server-side regression — the extension correctly calls the same endpoint and parameters used by the official Microsoft Graph Explorer, but the API fails specifically for?lang=powershell.Since the extension has no control over the external API, this PR adds a client-side fallback.
Solution
When the DevX API fails for PowerShell (HTTP error or network failure), the extension now generates idiomatic PowerShell snippets locally using
Invoke-MgGraphRequestfrom the Microsoft Graph PowerShell SDK.What changed (
src/common/client.js)generateLocalPowerShellSnippet()— Produces complete PowerShell snippets withImport-Module,Connect-MgGraph, andInvoke-MgGraphRequestformatPowerShellValue()— Recursively converts JSON request bodies into PowerShell hashtable literals (nested objects, arrays,$true/$false/$null, numbers, strings with proper escaping)buildDevxUri()— Extracted and simplified the DevX API URL construction logicgetSnippetFromDevX()— Refactored main function with a single fallback path (replaces duplicated error handling)response.text()was missingawaiton the success pathWhat didn't change
SyntaxHighlightercomponentExample output
For a
GET /v1.0/merequest, the fallback generates:For a
POSTwith a JSON body:Evidence
Before (PowerShell selected — no snippet rendered)
After (PowerShell selected — fallback snippet rendered)