Module: LanguageOperator::Errors

Defined in:
lib/language_operator/errors.rb

Overview

Standardized error formatting module for consistent error messages across tools

Class Method Summary collapse

Class Method Details

.access_denied(context = 'check RBAC permissions') ⇒ String

Access denied error

Parameters:

  • context (String) (defaults to: 'check RBAC permissions')

    Additional context (default: "check RBAC permissions")

Returns:

  • (String)

    Formatted error message



30
31
32
# File 'lib/language_operator/errors.rb', line 30

def self.access_denied(context = 'check RBAC permissions')
  "Error: Access denied - #{context}"
end

.empty_field(field_name) ⇒ String

Empty/missing required field error

Parameters:

  • field_name (String)

    Name of the field

Returns:

  • (String)

    Formatted error message



69
70
71
# File 'lib/language_operator/errors.rb', line 69

def self.empty_field(field_name)
  "Error: #{field_name} cannot be empty"
end

.file_not_found(file_path, context = 'file') ⇒ String

File not found error

Parameters:

  • file_path (String)

    Path to the file that wasn't found

  • context (String) (defaults to: 'file')

    Additional context about what the file is for

Returns:

  • (String)

    Formatted error message



77
78
79
80
# File 'lib/language_operator/errors.rb', line 77

def self.file_not_found(file_path, context = 'file')
  "Error: #{context.capitalize} not found at '#{file_path}'. " \
    'Please check the file path exists and is accessible.'
end

.file_permission_denied(file_path, context = 'file') ⇒ String

File permission error

Parameters:

  • file_path (String)

    Path to the file with permission issues

  • context (String) (defaults to: 'file')

    Additional context about what the file is for

Returns:

  • (String)

    Formatted error message



86
87
88
89
# File 'lib/language_operator/errors.rb', line 86

def self.file_permission_denied(file_path, context = 'file')
  "Error: Permission denied reading #{context} '#{file_path}'. " \
    'Please check file permissions or run with appropriate access rights.'
end

.file_syntax_error(file_path, original_error, context = 'file') ⇒ String

File syntax error

Parameters:

  • file_path (String)

    Path to the file with syntax errors

  • original_error (String)

    Original error message from parser

  • context (String) (defaults to: 'file')

    Additional context about what the file is for

Returns:

  • (String)

    Formatted error message



96
97
98
99
# File 'lib/language_operator/errors.rb', line 96

def self.file_syntax_error(file_path, original_error, context = 'file')
  "Error: Syntax error in #{context} '#{file_path}': #{original_error}. " \
    'Please check the file for valid Ruby syntax.'
end

.invalid_json(param_name) ⇒ String

Invalid JSON parameter error

Parameters:

  • param_name (String)

    Name of the parameter

Returns:

  • (String)

    Formatted error message



37
38
39
# File 'lib/language_operator/errors.rb', line 37

def self.invalid_json(param_name)
  "Error: Invalid JSON in #{param_name} parameter"
end

.invalid_parameter(param_name, value, expected) ⇒ String

Invalid parameter value error

Parameters:

  • param_name (String)

    Parameter name

  • value (String)

    Invalid value

  • expected (String)

    Expected format/value

Returns:

  • (String)

    Formatted error message



54
55
56
# File 'lib/language_operator/errors.rb', line 54

def self.invalid_parameter(param_name, value, expected)
  "Error: Invalid #{param_name} '#{value}'. Expected: #{expected}"
end

.missing_config(missing_vars) ⇒ String

Missing configuration error

Parameters:

  • missing_vars (String, Array<String>)

    Missing variable(s)

Returns:

  • (String)

    Formatted error message



44
45
46
47
# File 'lib/language_operator/errors.rb', line 44

def self.missing_config(missing_vars)
  vars = Array(missing_vars).join(', ')
  "Error: Missing configuration: #{vars}"
end

.not_found(resource_type, identifier) ⇒ String

Resource not found error

Parameters:

  • resource_type (String)

    Type of resource (e.g., "Pod", "LanguageAgent")

  • identifier (String)

    Resource identifier (name, ID, etc.)

Returns:

  • (String)

    Formatted error message



23
24
25
# File 'lib/language_operator/errors.rb', line 23

def self.not_found(resource_type, identifier)
  "Error: #{resource_type} not found - #{identifier}"
end

.operation_failed(operation, reason) ⇒ String

Generic operation failed error

Parameters:

  • operation (String)

    Operation that failed

  • reason (String)

    Reason for failure

Returns:

  • (String)

    Formatted error message



62
63
64
# File 'lib/language_operator/errors.rb', line 62

def self.operation_failed(operation, reason)
  "Error: #{operation} failed - #{reason}"
end

.path_traversal_blocked(context = 'file operation') ⇒ String

Path traversal security error

Parameters:

  • context (String) (defaults to: 'file operation')

    Context about what operation was attempted

Returns:

  • (String)

    Formatted error message



104
105
106
107
108
# File 'lib/language_operator/errors.rb', line 104

def self.path_traversal_blocked(context = 'file operation')
  "Error: Path traversal attempt blocked during #{context}. " \
    'File path must be within allowed directories. ' \
    'Use relative paths or configure LANGOP_ALLOWED_PATHS if needed.'
end