AykutSarac/jsoncrack.com · info
Please select some text first!
Error message
Please select some text first!
What it means
When the VS Code command jsoncrack-vscode.start.selected runs, it checks editor.selection.isEmpty; if nothing is selected it shows this informational message and returns early. This is a deliberate input guard, not an exception — the command requires a text selection to populate the webview.
Source
Thrown at apps/vscode/ext-src/extension.ts:31
context.subscriptions.push(
vscode.commands.registerCommand("jsoncrack-vscode.start", () =>
createWebviewForActiveEditor(context)
),
vscode.commands.registerCommand("jsoncrack-vscode.start.specific", (content?: string) =>
createWebviewForContent(context, content)
),
vscode.commands.registerCommand("jsoncrack-vscode.start.selected", () =>
createWebviewForSelectedText(context)
)
);
}
// create webview for selected text
async function createWebviewForSelectedText(context: vscode.ExtensionContext) {
const editor = vscode.window.activeTextEditor;
if (editor && editor.selection.isEmpty) {
vscode.window.showInformationMessage("Please select some text first!");
return;
}
const selectedText = editor?.document.getText(editor.selection);
// Create the webview panel and send the selected JSON content
const panel = createWebviewPanel(context, getPanelTitle(editor?.document));
panel.webview.postMessage({
json: selectedText,
});
const onReceiveMessage = panel.webview.onDidReceiveMessage(e => {
if (e === "ready") {
panel.webview.postMessage({
json: selectedText,
});
}
});View on GitHub (pinned to 3c9af69e23)
Solutions
- Select text (or Select All) first, then re-run the command.
- If whole-document behavior is desired, fall back to editor.document.getText() when the selection is empty (as the start command does).
- Point the user toward the non-selected command via the message.
- Rebind the keybinding if it is triggered accidentally.
Example fix
// before
if (editor && editor.selection.isEmpty) {
vscode.window.showInformationMessage("Please select some text first!");
return;
}
const selectedText = editor?.document.getText(editor.selection);
// after
let selectedText: string | undefined;
if (!editor || editor.selection.isEmpty) {
selectedText = editor?.document.getText();
if (!selectedText) {
vscode.window.showInformationMessage("Please select some text first!");
return;
}
} else {
selectedText = editor.document.getText(editor.selection);
} Defensive patterns
Strategy: validation
Validate before calling
function hasSelection(editor?: vscode.TextEditor): editor is vscode.TextEditor {
return !!editor && !editor.selection.isEmpty;
} Type guard
function hasSelection(editor?: vscode.TextEditor): editor is vscode.TextEditor {
return !!editor && !editor.selection.isEmpty;
} Prevention
- If whole-document behavior is acceptable, fall back to document.getText() when the selection is empty.
- Bind the 'selected' command to a distinct keybinding from the 'start' command so users pick the right one.
- Surface a hint pointing to the non-selected command when the guard triggers.
When it happens
Trigger: Invoking the 'Open Selected' command via palette or keybinding with the cursor at a single position (no range selected); running the command in an editor with no active text; empty new untitled file.
Common situations: User expects the command to auto-select the whole document; command bound to a key hit accidentally; empty file.
Related errors
AI-assisted analysis of AykutSarac/jsoncrack.com@3c9af69e23 (2026-08-12).
Data as JSON: /api/errors/2bbcd7c091df4f33.
Report an issue: GitHub.