UNPKG

dev-lamp

Version:

Your friendly lighthouse performance companion - 100% local

74 lines 3.38 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ErrorHandler = void 0; const chalk_1 = __importDefault(require("chalk")); class ErrorHandler { handle(error) { if (error.code === 'ECONNREFUSED') { this.showConnectionError(error); } else if (error.code === 'CHROME_NOT_FOUND') { this.showChromeError(); } else if (error.code === 'INVALID_URL') { this.showUrlError(error); } else if (error.name === 'LighthouseError') { this.showLighthouseError(error); } else { this.showGenericError(error); } } showConnectionError(error) { console.error(chalk_1.default.red('\nERROR: Connection Failed\n')); console.error('Could not connect to the URL. Please check:'); console.error(' 1. Is your local server running?'); console.error(' 2. Is the URL correct?'); console.error(' 3. Try: ' + chalk_1.default.cyan('npm run dev') + ' first\n'); if (error.url) { console.error(chalk_1.default.gray(`URL attempted: ${error.url}`)); } } showChromeError() { console.error(chalk_1.default.red('\nERROR: Chrome Not Found\n')); console.error('dev-lamp needs Chrome to run Lighthouse audits.\n'); console.error('Please either:'); console.error(' 1. Install Google Chrome from https://google.com/chrome'); console.error(' 2. Specify Chrome path: ' + chalk_1.default.cyan('dev-lamp analyze <url> --chrome-path "/path/to/chrome"')); console.error('\nCommon Chrome locations:'); console.error(' macOS: /Applications/Google Chrome.app/Contents/MacOS/Google Chrome'); console.error(' Windows: C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe'); console.error(' Linux: /usr/bin/google-chrome'); } showUrlError(error) { console.error(chalk_1.default.red('\nERROR: Invalid URL\n')); console.error(`The URL "${error.url}" is not valid.\n`); console.error('Valid URL examples:'); console.error(' ' + chalk_1.default.green('http://localhost:3000')); console.error(' ' + chalk_1.default.green('http://127.0.0.1:8080')); console.error(' ' + chalk_1.default.green('https://example.com')); } showLighthouseError(error) { console.error(chalk_1.default.red('\nERROR: Lighthouse Error\n')); console.error('Failed to run Lighthouse audit:'); console.error(error.message); console.error('\nPossible solutions:'); console.error(' 1. Check if the URL is accessible'); console.error(' 2. Try running with --no-headless to see Chrome'); console.error(' 3. Check Chrome installation'); } showGenericError(error) { console.error(chalk_1.default.red('\nERROR: Unexpected Error\n')); console.error(error.message || error); if (error.stack && process.env.DEBUG) { console.error(chalk_1.default.gray('\nStack trace:')); console.error(chalk_1.default.gray(error.stack)); } } } exports.ErrorHandler = ErrorHandler; //# sourceMappingURL=error-handler.js.map