Skip to content

Fix/powershell snippet fallback - #11

Merged
merill merged 10 commits into
merill:mainfrom
jorgeasaurus:fix/powershell-snippet-fallback
Apr 4, 2026
Merged

merill merged 10 commits into
merill:mainfrom
jorgeasaurus:fix/powershell-snippet-fallback

Conversation

@jorgeasaurus

Copy link
Copy Markdown
Contributor

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-MgGraphRequest from the Microsoft Graph PowerShell SDK.

What changed (src/common/client.js)

  • generateLocalPowerShellSnippet() — Produces complete PowerShell snippets with Import-Module, Connect-MgGraph, and Invoke-MgGraphRequest
  • formatPowerShellValue() — 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 logic
  • getSnippetFromDevX() — Refactored main function with a single fallback path (replaces duplicated error handling)
  • Bug fix: response.text() was missing await on the success path

What didn't change

  • Other languages continue using the DevX API as before
  • No UI changes — snippets render in the same SyntaxHighlighter component
  • If/when the DevX API is fixed, PowerShell will automatically use it again (fallback only fires on failure)

Example output

For a GET /v1.0/me request, the fallback generates:

Import-Module Microsoft.Graph

Connect-MgGraph

Invoke-MgGraphRequest -Method GET -Uri "https://graph.microsoft.com/v1.0/me"

For a POST with a JSON body:

Import-Module Microsoft.Graph

Connect-MgGraph

$params = @{
	displayName = "Test User"
	accountEnabled = $true
	passwordProfile = @{
		forceChangePasswordNextSignIn = $true
		password = "xWwvJ]6NMw+bWH-d"
	}
}

Invoke-MgGraphRequest -Method POST -Uri "https://graph.microsoft.com/v1.0/users" -Body ($params | ConvertTo-Json -Depth 10) -ContentType "application/json"

Evidence

Before (PowerShell selected — no snippet rendered)

before

After (PowerShell selected — fallback snippet rendered)

after

actions-user and others added 2 commits August 15, 2025 15:41
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>

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Comment thread src/common/client.js
Comment thread src/common/client.js
Comment thread src/common/client.js Outdated
Comment thread src/common/client.js
jorgeasaurus and others added 8 commits April 4, 2026 09:59
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>
@merill merill closed this Apr 4, 2026
@merill merill reopened this Apr 4, 2026
@merill
merill merged commit 6e74e95 into merill:main Apr 4, 2026
1 check passed
@merill

merill commented Apr 4, 2026

Copy link
Copy Markdown
Owner

@jorgeasaurus Tx a lot for the PR.

I've already merged it. Are you making any new updates?

@jorgeasaurus

Copy link
Copy Markdown
Contributor Author

You're welcome. No other changes at this time.

@merill

merill commented Apr 4, 2026

Copy link
Copy Markdown
Owner

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.

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.

PowerShell code snippets not appearing

3 participants