errors

package
v0.4.18 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 18, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package errors provides error types for MessageFormat 2.0 implementation Following TypeScript errors.ts module with Go best practices

Index

Constants

View Source
const (
	ErrorTypeEmptyToken                = "empty-token"
	ErrorTypeBadEscape                 = "bad-escape"
	ErrorTypeBadInputExpression        = "bad-input-expression"
	ErrorTypeDuplicateAttribute        = "duplicate-attribute"
	ErrorTypeDuplicateDeclaration      = "duplicate-declaration"
	ErrorTypeDuplicateOptionName       = "duplicate-option-name"
	ErrorTypeDuplicateVariant          = "duplicate-variant"
	ErrorTypeExtraContent              = "extra-content"
	ErrorTypeKeyMismatch               = "key-mismatch"
	ErrorTypeParseError                = "parse-error"
	ErrorTypeMissingFallback           = "missing-fallback"
	ErrorTypeMissingSelectorAnnotation = "missing-selector-annotation"
	ErrorTypeMissingSyntax             = "missing-syntax"
)

Syntax error types

View Source
const (
	ErrorTypeBadFunctionResult    = "bad-function-result"
	ErrorTypeBadOperand           = "bad-operand"
	ErrorTypeBadOption            = "bad-option"
	ErrorTypeUnresolvedVariable   = "unresolved-variable"
	ErrorTypeUnsupportedOperation = "unsupported-operation"
)

Resolution error types

View Source
const (
	ErrorTypeBadSelector = "bad-selector"
	ErrorTypeNoMatch     = "no-match"
)

Selection error types

View Source
const (
	ErrorTypeNotFormattable  = "not-formattable"
	ErrorTypeUnknownFunction = "unknown-function"
)

Formatting error types

Variables

This section is empty.

Functions

This section is empty.

Types

type MessageDataModelError added in v0.2.0

type MessageDataModelError struct {
	*MessageSyntaxError
}

MessageDataModelError represents errors in the message data model TypeScript original code:

export class MessageDataModelError extends MessageSyntaxError {
  declare type:
    | 'duplicate-declaration'
    | 'duplicate-variant'
    | 'key-mismatch'
    | 'missing-fallback'
    | 'missing-selector-annotation';
  constructor(type: typeof MessageDataModelError.prototype.type, node: Node) {
    const { start, end } = node[cstKey] ?? { start: -1, end: -1 };
    super(type, start, end);
  }
}

func NewDuplicateDeclarationError added in v0.2.0

func NewDuplicateDeclarationError(node Node) *MessageDataModelError

NewDuplicateDeclarationError creates a duplicate declaration error

func NewMessageDataModelError added in v0.2.0

func NewMessageDataModelError(errorType string, node Node) *MessageDataModelError

NewMessageDataModelError creates a new data model error TypeScript original code: MessageDataModelError constructor

func NewMissingFallbackError added in v0.2.0

func NewMissingFallbackError(node Node) *MessageDataModelError

NewMissingFallbackError creates a missing fallback error

type MessageError

type MessageError struct {
	Type    string // Error type classification
	Message string // Error message description
}

MessageError represents the base error class used by MessageFormat TypeScript original code:

export class MessageError extends Error {
  type:
    | 'not-formattable'
    | 'unknown-function'
    | typeof MessageResolutionError.prototype.type
    | typeof MessageSelectionError.prototype.type
    | typeof MessageSyntaxError.prototype.type;
  constructor(type: typeof MessageError.prototype.type, message: string) {
    super(message);
    this.type = type;
  }
}

func NewMessageError added in v0.2.0

func NewMessageError(errorType, message string) *MessageError

NewMessageError creates a new base message error

func (*MessageError) Error

func (e *MessageError) Error() string

Error implements the error interface

func (*MessageError) ErrorType added in v0.3.6

func (e *MessageError) ErrorType() string

ErrorType returns the error type classification.

func (*MessageError) Is added in v0.3.0

func (e *MessageError) Is(target error) bool

Is implements error comparison for errors.Is()

type MessageFunctionError added in v0.3.6

type MessageFunctionError struct {
	*MessageError
	Source string // Source text where error occurred, defaults to '�'
	Cause  error  // Optional underlying cause error
}

MessageFunctionError represents message function errors TypeScript original code:

export class MessageFunctionError extends MessageError {
  declare type:
    | 'bad-operand'
    | 'bad-option'
    | 'bad-variant-key'
    | 'function-error'
    | 'not-formattable'
    | 'unsupported-operation';
  source: string;
  cause?: unknown;
  constructor(
    type: typeof MessageFunctionError.prototype.type,
    message: string
  ) {
    super(type, message);
    this.source = '�';
  }
}

func NewMessageFunctionError added in v0.3.6

func NewMessageFunctionError(errorType, message string) *MessageFunctionError

NewMessageFunctionError creates a new function error TypeScript original code: MessageFunctionError constructor

func (*MessageFunctionError) SetCause added in v0.3.6

func (e *MessageFunctionError) SetCause(cause error)

SetCause sets the cause for a function error

func (*MessageFunctionError) SetSource added in v0.3.6

func (e *MessageFunctionError) SetSource(source string)

SetSource sets the source for a function error

func (*MessageFunctionError) Unwrap added in v0.3.6

func (e *MessageFunctionError) Unwrap() error

Unwrap returns the underlying cause error for error wrapping

type MessageResolutionError added in v0.2.0

type MessageResolutionError struct {
	*MessageError
	Source string // Source text where error occurred
}

MessageResolutionError represents message runtime resolution errors TypeScript original code:

export class MessageResolutionError extends MessageError {
  declare type:
    | 'bad-function-result'
    | 'bad-operand'
    | 'bad-option'
    | 'unresolved-variable'
    | 'unsupported-operation';
  source: string;
  constructor(
    type: typeof MessageResolutionError.prototype.type,
    message: string,
    source: string
  ) {
    super(type, message);
    this.source = source;
  }
}

func NewBadFunctionResultError added in v0.2.0

func NewBadFunctionResultError(message, source string) *MessageResolutionError

NewBadFunctionResultError creates a bad function result error

func NewBadOperandError added in v0.2.0

func NewBadOperandError(message, source string) *MessageResolutionError

NewBadOperandError creates a bad operand error

func NewBadOptionError added in v0.2.0

func NewBadOptionError(message, source string) *MessageResolutionError

NewBadOptionError creates a bad option error

func NewMessageResolutionError added in v0.2.0

func NewMessageResolutionError(errorType, message, source string) *MessageResolutionError

NewMessageResolutionError creates a new resolution error TypeScript original code: MessageResolutionError constructor

func NewUnknownFunctionError added in v0.2.0

func NewUnknownFunctionError(functionName, source string) *MessageResolutionError

NewUnknownFunctionError creates an unknown function error

func NewUnresolvedVariableError added in v0.2.0

func NewUnresolvedVariableError(variableName, source string) *MessageResolutionError

NewUnresolvedVariableError creates an unresolved variable error

type MessageSelectionError added in v0.2.0

type MessageSelectionError struct {
	*MessageError
	Cause error // Underlying cause error (optional)
}

MessageSelectionError represents errors in message selection TypeScript original code:

export class MessageSelectionError extends MessageError {
  declare type: 'bad-selector' | 'no-match';
  cause?: unknown;
  constructor(
    type: typeof MessageSelectionError.prototype.type,
    cause?: unknown
  ) {
    super(type, `Selection error: ${type}`);
    if (cause !== undefined) this.cause = cause;
  }
}

func NewBadSelectorError added in v0.2.0

func NewBadSelectorError(cause error) *MessageSelectionError

NewBadSelectorError creates a bad selector error

func NewMessageSelectionError added in v0.2.0

func NewMessageSelectionError(errorType string, cause error) *MessageSelectionError

NewMessageSelectionError creates a new selection error TypeScript original code: MessageSelectionError constructor

func NewNoMatchError added in v0.2.0

func NewNoMatchError(cause error) *MessageSelectionError

NewNoMatchError creates a no match error

func (*MessageSelectionError) Unwrap added in v0.2.0

func (e *MessageSelectionError) Unwrap() error

Unwrap returns the underlying cause error for error wrapping

type MessageSyntaxError added in v0.2.0

type MessageSyntaxError struct {
	*MessageError
	Start int // Start position in source
	End   int // End position in source
}

MessageSyntaxError represents errors in the message syntax TypeScript original code:

export class MessageSyntaxError extends MessageError {
  declare type:
    | 'empty-token'
    | 'bad-escape'
    | 'bad-input-expression'
    | 'duplicate-attribute'
    | 'duplicate-declaration'
    | 'duplicate-option-name'
    | 'duplicate-variant'
    | 'extra-content'
    | 'key-mismatch'
    | 'parse-error'
    | 'missing-fallback'
    | 'missing-selector-annotation'
    | 'missing-syntax';
  start: number;
  end: number;
  constructor(
    type: typeof MessageSyntaxError.prototype.type,
    start: number,
    end?: number,
    expected?: string
  ) {
    let message = expected ? `Missing ${expected}` : type;
    if (start >= 0) message += ` at ${start}`;
    super(type, message);
    this.start = start;
    this.end = end ?? start + 1;
  }
}

func NewCustomSyntaxError added in v0.2.0

func NewCustomSyntaxError(message string) *MessageSyntaxError

NewCustomSyntaxError creates a syntax error with a custom message

func NewMessageSyntaxError added in v0.2.0

func NewMessageSyntaxError(errorType string, start int, end *int, expected *string) *MessageSyntaxError

NewMessageSyntaxError creates a new syntax error TypeScript original code: MessageSyntaxError constructor

type Node added in v0.2.0

type Node interface {
	// GetPosition returns the start and end positions if available
	GetPosition() (start, end int)
}

Node represents a minimal interface for data model nodes to avoid import cycles

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL