portfree
Version:
A cross-platform CLI tool for managing processes running on specific ports
44 lines • 1.51 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.PermissionError = void 0;
/**
* Custom error class for permission-related errors
* Used when operations fail due to insufficient privileges
*/
class PermissionError extends Error {
/**
* Create a new PermissionError
* @param message - Error message describing the permission issue
* @param pid - Process ID related to the permission error (optional)
*/
constructor(message, pid = null) {
super(message);
this.name = 'PermissionError';
this.code = 'PERMISSION_ERROR';
this.pid = pid;
// Maintains proper stack trace for where our error was thrown (only available on V8)
if (Error.captureStackTrace) {
Error.captureStackTrace(this, PermissionError);
}
}
/**
* Get user-friendly error message with suggestions
* @returns Formatted error message
*/
getUserMessage() {
let message = this.message;
if (this.pid) {
message += ` (PID: ${this.pid})`;
}
message += '\n\nSuggestion: Try running the command with elevated privileges:';
if (process.platform === 'win32') {
message += '\n- Run Command Prompt or PowerShell as Administrator';
}
else {
message += '\n- Use sudo: sudo freeport';
}
return message;
}
}
exports.PermissionError = PermissionError;
//# sourceMappingURL=permission-error.js.map