or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

exceptions.mdindex.mdlogging.mdmerging.mdutils.md
tile.json

exceptions.mddocs/

Exception Handling

Specialized exception classes for different error scenarios in AutoRest operations, providing structured error handling with exit codes and contextual information.

Capabilities

Base Exception

Core exception class with exit code support for AutoRest operations.

class Exception extends Error {
  constructor(message: string, exitCode?: number);
  exitCode: number;
}

Usage Example:

import { Exception } from "@autorest/common";

try {
  // Some AutoRest operation
  throw new Exception("Configuration parsing failed", 2);
} catch (error) {
  if (error instanceof Exception) {
    console.error(`Error: ${error.message}`);
    process.exit(error.exitCode);
  }
}

Operation Cancellation Exception

Exception thrown when an operation is cancelled by user request or system constraint.

class OperationCanceledException extends Exception {
  constructor(message?: string, exitCode?: number);
  exitCode: number;
}

Usage Example:

import { OperationCanceledException } from "@autorest/common";

function processWithCancellation(signal: AbortSignal) {
  if (signal.aborted) {
    throw new OperationCanceledException("Operation was cancelled by user", 130);
  }
  
  // Continue processing...
}

Outstanding Task Already Completed Exception

Exception thrown when attempting to complete a task that has already been completed.

class OutstandingTaskAlreadyCompletedException extends Exception {
  constructor();
}

Usage Example:

import { OutstandingTaskAlreadyCompletedException } from "@autorest/common";

class TaskManager {
  private completedTasks = new Set<string>();
  
  completeTask(taskId: string) {
    if (this.completedTasks.has(taskId)) {
      throw new OutstandingTaskAlreadyCompletedException();
    }
    
    this.completedTasks.add(taskId);
  }
}

Operation Aborted Exception

Exception thrown when an operation is aborted due to critical error or system failure.

class OperationAbortedException extends Exception {
  constructor();
}

Usage Example:

import { OperationAbortedException } from "@autorest/common";

function processFile(filePath: string) {
  if (!fs.existsSync(filePath)) {
    throw new OperationAbortedException();
  }
  
  // Continue processing...
}

Plugin User Error

Exception specific to plugin-related user errors, providing plugin context information.

class PluginUserError extends Error {
  constructor(pluginName: string);
  code: string; // Always "PluginUserError"
  pluginName: string;
}

Usage Example:

import { PluginUserError } from "@autorest/common";

class PluginManager {
  executePlugin(pluginName: string, config: any) {
    try {
      // Plugin execution logic
    } catch (error) {
      throw new PluginUserError(pluginName);
    }
  }
}

// Error handling
try {
  pluginManager.executePlugin("swagger-codegen", config);
} catch (error) {
  if (error instanceof PluginUserError) {
    console.error(`Plugin error in ${error.pluginName}: ${error.message}`);
    console.error(`Error code: ${error.code}`); // "PluginUserError"
  }
}

Exception Hierarchy

All AutoRest exceptions inherit from the base Exception class:

Error (built-in)
└── Exception
    ├── OperationCanceledException
    ├── OutstandingTaskAlreadyCompletedException
    └── OperationAbortedException

Error (built-in)
└── PluginUserError

Error Handling Patterns

Basic Exception Handling

import { Exception, OperationCanceledException } from "@autorest/common";

function safeOperation() {
  try {
    // Some operation that might throw
    performAutoRestOperation();
  } catch (error) {
    if (error instanceof OperationCanceledException) {
      console.log("Operation was cancelled");
      return { cancelled: true };
    } else if (error instanceof Exception) {
      console.error(`AutoRest error: ${error.message}`);
      process.exit(error.exitCode);
    } else {
      console.error("Unexpected error:", error);
      throw error;
    }
  }
}

Plugin Error Handling

import { PluginUserError } from "@autorest/common";

function handlePluginExecution(pluginName: string) {
  try {
    executePlugin(pluginName);
  } catch (error) {
    if (error instanceof PluginUserError) {
      // Handle plugin-specific errors
      logPluginError(error.pluginName, error.message);
      return { success: false, pluginError: true };
    }
    throw error;
  }
}