🔥 Prince Error Sound — VS Code Extension
A Visual Studio Code extension that plays a custom Prince sound effect whenever a program executed through VS Code/Code Runner finishes with an error.
The goal is simple:
Code fails → Prince plays. 🔊👑
📌 Features
- 🔊 Plays a custom
prince.mp3 sound when an execution fails.
- 💻 Designed for Windows.
- 🧑💻 Works with JavaScript, Python, Node.js, and other languages that can be executed through VS Code/Code Runner.
- ⚡ Uses Windows PowerShell
MediaPlayer for audio playback.
- 🪶 Lightweight extension with no external audio application required.
- 🛠️ Can be launched and debugged directly from VS Code using
F5.
- 📋 Logs extension activity in the VS Code Debug Console.
🖥️ Requirements
Operating System
Currently supported:
- ✅ Windows 10
- ✅ Windows 11
The extension currently uses:
powershell.exe
System.Windows.Media.MediaPlayer
PresentationCore
Therefore, the current implementation is Windows-specific.
Linux/macOS support would require a different audio implementation.
🧰 Required Software
1. Visual Studio Code
Install VS Code.
The extension is developed and tested using VS Code's Extension Development Host.
2. Node.js
Node.js is required for extension development and package management.
Recommended:
Check installation:
node --version
npm --version
Example:
Node.js: v26.x
npm: 11.x
If PowerShell blocks npm.ps1, use:
npm.cmd --version
and:
npm.cmd install
3. Code Runner
The extension is designed to work with executions made through:
Code Runner by Jun Han
Install it from the VS Code Extensions marketplace.
Search:
Code Runner
📁 Project Structure
The project should look like this:
Prince-Extension/
│
├── .vscode/
│ └── launch.json
│
├── sounds/
│ └── prince.mp3
│
├── extension.js
├── package.json
├── package-lock.json
├── test.js
│
└── extension.backup.js
🔊 Sound File Requirement
The extension expects the sound file at:
sounds/prince.mp3
Therefore:
Prince-Extension/
└── sounds/
└── prince.mp3
The file must be named exactly:
prince.mp3
The extension constructs the path automatically:
const soundFile = path.join(
context.extensionPath,
'sounds',
'prince.mp3'
);
📦 package.json
The extension metadata is defined in package.json.
Example:
{
"name": "prince-error-sound",
"displayName": "Prince Error Sound",
"description": "Plays a custom sound when a coding error occurs.",
"version": "0.0.1",
"publisher": "ritesh",
"engines": {
"vscode": "^1.85.0"
},
"main": "./extension.js",
"activationEvents": [
"*"
],
"categories": [
"Other"
],
"dependencies": {
"play-sound": "^1.1.6"
}
}
Note: The current extension.js uses PowerShell directly for playback, so play-sound is not required by the current implementation. It may be removed later if we decide not to use it.
📥 Installing Dependencies
Open PowerShell in the project directory:
cd C:\Users\ritesh\Desktop\Prince-Extension
Then:
npm.cmd install
If play-sound is listed as a dependency:
npm.cmd install play-sound
Verify:
npm.cmd list play-sound
🐛 Development Setup
1. Open the project
Open:
C:\Users\ritesh\Desktop\Prince-Extension
in VS Code.
Create:
.vscode/launch.json
Example:
{
"version": "0.2.0",
"configurations": [
{
"name": "Run Prince Extension",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}"
]
}
]
}
▶️ Running the Extension
Open:
Run and Debug
using:
Ctrl + Shift + D
Select:
Run Prince Extension
Then press:
F5
VS Code should open a new:
Extension Development Host
window.
✅ Confirming the Extension Is Running
In the Debug Console, you should see:
🔥 PRINCE ERROR SOUND EXTENSION IS ACTIVE 🔥
and:
👂 Waiting for Code Runner errors...
This confirms that:
- The extension loaded.
extension.js was executed.
- The
activate() function ran successfully.
🧪 Testing
Create a test JavaScript file:
console.log(x);
Since x isn't defined, Node.js should produce:
ReferenceError: x is not defined
and Code Runner should finish with:
[Done] exited with code=1
The extension should detect the non-zero exit code and play:
sounds/prince.mp3
🔊 Testing Audio Independently
Before debugging the extension, test whether Windows can play the MP3.
Run this in PowerShell:
$sound = "C:\Users\ritesh\Desktop\Prince-Extension\sounds\prince.mp3"
Add-Type -AssemblyName PresentationCore
$p = New-Object System.Windows.Media.MediaPlayer
$p.Open([Uri]::new($sound))
Start-Sleep -Seconds 2
$p.Play()
Start-Sleep -Seconds 10
$p.Stop()
$p.Close()
If you hear the sound:
🔊 Audio system working
If you don't:
🔇 Investigate Windows audio/file path
🔍 Verify Sound File
Run:
Test-Path "C:\Users\ritesh\Desktop\Prince-Extension\sounds\prince.mp3"
Expected:
True
If it returns:
False
the MP3 is missing or the path is incorrect.
🧠 How the Extension Works
The extension starts when VS Code activates it.
VS Code
│
▼
extension.js
│
▼
activate()
│
▼
Wait for execution
│
▼
Program runs
│
├── Success → Do nothing
│
└── Error
│
▼
Detect non-zero exit code
│
▼
playPrinceSound()
│
▼
powershell.exe
│
▼
Windows MediaPlayer
│
▼
prince.mp3 🔊👑
🔧 Audio Implementation
The current implementation uses Node.js:
const { execFile } = require('child_process');
PowerShell is launched using:
execFile(
'powershell.exe',
[...]
);
PowerShell loads:
PresentationCore
and creates:
System.Windows.Media.MediaPlayer
The MP3 is then played for approximately 10 seconds.
📋 Debug Logs
The extension prints messages into the VS Code Debug Console.
Extension started
🔥 PRINCE ERROR SOUND EXTENSION IS ACTIVE 🔥
Waiting
👂 Waiting for Code Runner errors...
Execution detected
💻 Terminal finished: ...
Exit code
📊 Exit code: 1
Error detected
❌ Failed terminal command detected!
Sound starting
🔊 Playing Prince sound...
Sound successfully launched
✅ Prince sound played!
⚠️ Important: Code Runner vs Integrated Terminal
There is an important distinction between:
Integrated Terminal
Example:
node test.js
and:
Code Runner
Example:
[Running] node "test.js"
...
[Done] exited with code=1
These are not necessarily exposed to VS Code through the same API.
The original extension used:
vscode.window.onDidEndTerminalShellExecution
This works with terminal shell execution events, but Code Runner's output may be handled differently.
Therefore, Code Runner detection is the main area of the extension that may require further implementation.
🛠️ Troubleshooting
Problem: npm is not recognized
Check:
node --version
If Node works but npm gives an execution-policy error, use:
npm.cmd --version
and:
npm.cmd install
Problem: Extension does not activate
Check:
Run and Debug
and make sure:
Run Prince Extension
is selected.
Then press:
F5
Look for:
🔥 PRINCE ERROR SOUND EXTENSION IS ACTIVE 🔥
Problem: Python F5 runs instead
This means VS Code is using the Python debugger instead of the extension debugger.
Open:
Run and Debug
and select:
Run Prince Extension
before pressing F5.
Problem: Sound doesn't play
First test the MP3 directly with the PowerShell audio test in this README.
If direct playback works but the extension doesn't play it, the problem is most likely error detection, not audio.
Problem: JavaScript error occurs but no sound
Example:
ReferenceError: x is not defined
followed by:
[Done] exited with code=1
If there is no:
🔊 Playing Prince sound...
then the extension didn't detect Code Runner's failure.
Check the Debug Console.
🧹 Backup
Before making major changes to extension.js, create a backup:
Copy-Item extension.js extension.backup.js
Restore it with:
Copy-Item extension.backup.js extension.js
🚀 Future Improvements
Potential future versions can add:
- 🔊 Different sounds for different error types.
- 🎵 Random Prince sounds.
- ⏱️ Configurable sound duration.
- 🔇 Enable/disable sound.
- 🎚️ Volume control.
- 🧑💻 Per-language configuration.
- 📝 Error-type detection.
- 🐍 Python support.
- 🟨 JavaScript/Node.js support.
- ☕ Java support.
- 🐘 PHP support.
- 🦀 Rust support.
- 🐹 Go support.
- 🐳 Docker command failure detection.
- 🖥️ Cross-platform Linux/macOS audio support.
- ⚙️ VS Code settings for customization.
- 🔔 Desktop notifications.
- 📊 Error statistics.
📌 Current Status
| Component |
Status |
| VS Code extension |
✅ |
extension.js |
✅ |
| Extension activation |
✅ |
| Windows support |
✅ |
| PowerShell audio |
✅ |
prince.mp3 playback |
✅ |
| Node.js |
✅ |
| npm |
✅ |
| Code Runner |
✅ Installed |
| JavaScript execution |
✅ |
| Error detection |
🔧 In development |
| Automatic Prince sound on Code Runner error |
🔧 In development |
| Linux support |
❌ |
| macOS support |
❌ |
👑 Project Goal
The final experience should be:
Write code
↓
Run code
↓
├── ✅ Successful
│ ↓
│ Nothing happens
│
└── ❌ Error
↓
🔊 PRINCE!
👑 Prince Error Sound
Because every coding error deserves a soundtrack. 🔥
Version: 0.0.1
Platform: Windows
Author: Ritesh