A lightning-fast frontend build tool designed to leverage JavaScript's native ESM system for unbundled development with instant browser updates.
82
Build a utility module that integrates with Snowpack's error handling system to provide custom error reporting and recovery mechanisms during development and build processes.
Your module should provide functionality to:
Custom Error Handler: Create a handler that intercepts Snowpack build errors and logs them in a structured format (JSON) to a file named error-log.json. Each error entry should include timestamp, error type, message, and file path if available.
HMR Error Notification: Implement a function that can be called from Snowpack's development server to send custom error notifications to connected clients when HMR updates fail. The notification should include error details and suggested fixes.
Graceful Fallback: Create a mechanism that detects when a module fails to load during development and provides a fallback response (e.g., returning a stub module) instead of crashing the dev server.
Error Recovery Reporter: Build a function that analyzes the error log and generates a summary report showing the most common error types, affected files, and error frequency.
Your implementation should:
@generates
/**
* Logs a Snowpack build error to error-log.json
* @param {Error} error - The error object from Snowpack
* @param {Object} context - Additional context (filePath, mode)
*/
function logBuildError(error, context) {}
/**
* Sends HMR error notification to connected clients
* @param {Object} server - Snowpack server instance
* @param {Error} error - The HMR error
* @param {string} modulePath - Path to the module that failed
*/
function notifyHmrError(server, error, modulePath) {}
/**
* Provides a fallback stub module when a module fails to load
* @param {string} modulePath - Path to the failed module
* @returns {Object} Stub module with safe defaults
*/
function getFallbackModule(modulePath) {}
/**
* Analyzes error log and generates summary report
* @returns {Promise<Object>} Report with error statistics
*/
async function generateErrorReport() {}
module.exports = {
logBuildError,
notifyHmrError,
getFallbackModule,
generateErrorReport
};When logBuildError is called with a NotFoundError for file "missing.js", it writes an entry to error-log.json with type "NotFoundError" and filePath "missing.js" @test
When logBuildError is called with a SyntaxError, it preserves the error stack trace in the logged entry @test
When notifyHmrError is called with an error for module "/src/app.js", it sends a message through the server's HMR connection with error details @test
When getFallbackModule is called with a path to a failed module, it returns an object with empty exports and a warning property @test
When generateErrorReport is called after logging 3 NotFoundErrors and 2 SyntaxErrors, it returns a report showing NotFoundError as the most common error type with count 3 @test
Provides the build tool and error handling infrastructure.
@satisfied-by
Install with Tessl CLI
npx tessl i tessl/npm-snowpackevals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10