Skip to content

Conversation

@ytallo
Copy link
Contributor

@ytallo ytallo commented Nov 3, 2025

Summary

This PR adds comprehensive error logging to Amplitude for all CLI commands in the @snap package. It implements a generic wrapAction helper that automatically logs errors to Amplitude with command context (command name, error message, error type, and stack trace) before rethrowing the error for Commander.js to handle.

Related Issues

Type of Change

  • New feature
  • Bug fix
  • Breaking change
  • Refactor
  • Other (please describe):

Checklist

  • I have read the CONTRIBUTING.md
  • My code follows the code style of this project
  • I have tested my changes locally
  • I have added tests where applicable
  • I have linked relevant issues
  • I have added screenshots for UI changes (if applicable)

Changes Made

Core Implementation

  • Created logCliError utility (packages/snap/src/utils/analytics.ts): Logs CLI errors to Amplitude with command name, error message, error type, and truncated stack trace
  • Created wrapAction helper: Generic wrapper function that wraps async command actions to automatically catch and log errors before rethrowing
  • Updated handler function (packages/snap/src/cloud/config-utils.ts): Enhanced existing error handler to log errors to Amplitude for commands using the handler pattern

Command Updates

Applied wrapAction to all CLI commands:

  • generate-types
  • install
  • dev
  • start
  • emit
  • generate step
  • generate openapi
  • docker setup
  • docker run
  • docker build

Commands using the handler wrapper (create, rules pull, cloud build, cloud deploy) automatically get error logging through the enhanced handler.

Key Features

  • Automatic error logging: All CLI command errors are logged to Amplitude with full context
  • Commander.js integration: Follows Commander.js best practices by wrapping actions rather than intercepting at parse level
  • No breaking changes: Errors are logged but still handled by Commander.js for display
  • Flush on error: Ensures Amplitude events are flushed before process exit on errors

Additional Context

This implementation follows Commander.js best practices by wrapping individual command actions rather than catching errors at the program parse level. This allows Commander.js to handle error display while we log errors to Amplitude for monitoring and debugging purposes.

@vercel
Copy link

vercel bot commented Nov 3, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
motia-docs Ready Ready Preview Comment Nov 3, 2025 6:45pm
motia-ui Ready Ready Preview Comment Nov 3, 2025 6:45pm

@github-actions
Copy link

github-actions bot commented Nov 3, 2025

E2E Test Results ✅

All tests have completed. Tests passed.

Matrix: 2 OS (Ubuntu, macOS) × 2 Templates (Node.js, Python) = 4 jobs

View detailed test results


This comment is automatically posted by the PR E2E Results workflow.

@ytallo ytallo merged commit 1150789 into main Nov 4, 2025
18 checks passed
@ytallo ytallo deleted the feat/add-cli-command-error-tracking branch November 4, 2025 17:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants