CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-snowpack

A lightning-fast frontend build tool designed to leverage JavaScript's native ESM system for unbundled development with instant browser updates.

82

1.22x
Overview
Eval results
Files

task.mdevals/scenario-6/

Snowpack Error Handler Utility

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.

Requirements

Your module should provide functionality to:

  1. 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.

  2. 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.

  3. 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.

  4. 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.

Implementation

Your implementation should:

  • Handle NotFoundError separately from other error types
  • Preserve source-mapped stack traces in error logs
  • Work with both development and build modes
  • Be non-blocking (errors should not prevent other modules from loading)

@generates

API

/**
 * 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
};

Test Cases

  • 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

Dependencies { .dependencies }

snowpack { .dependency }

Provides the build tool and error handling infrastructure.

@satisfied-by

Install with Tessl CLI

npx tessl i tessl/npm-snowpack

tile.json