Skip to main content

Class: Error

Defined in: src/lib/logger/components/error.ts:47 Represents an error or exception that occurred within the trace. The Error class captures detailed information about failures, exceptions, and error conditions, providing context for debugging and monitoring. Error

Examples

const error = container.error({
  id: 'err-001',
  message: 'Failed to connect to external API',
  code: 'CONNECTION_TIMEOUT',
  type: 'NetworkError',
});
// Capturing JavaScript errors
try {
  await riskyOperation();
} catch (err) {
  const error = container.error({
    id: 'operation-failure',
    message: err.message,
    name: err.name,
    type: 'JavaScriptError',
  });
}

Extends

Constructors

Constructor

new Error(config, writer): Error
Defined in: src/lib/logger/components/error.ts:66 Creates a new error log entry.

Parameters

config
ErrorConfig Configuration object defining the error details
writer
LogWriter Log writer instance for persisting the error

Returns

Error

Example

const error = container.error({
  id: 'validation-error',
  message: 'Invalid input parameters',
  code: 'VALIDATION_FAILED',
  type: 'ValidationError',
});

Overrides

BaseContainer.constructor

Accessors

id

Get Signature

get id(): string
Defined in: src/lib/logger/components/base.ts:80 Gets the unique identifier for this container.
Returns
string The container’s unique ID

Inherited from

BaseContainer.id

Methods

addMetadata()

addMetadata(metadata): void
Defined in: src/lib/logger/components/base.ts:124 Adds metadata to this container for additional context and debugging. Any data type could be added as the value in the metadata record.

Parameters

metadata
Record<string, unknown> Key-value pairs of metadata

Returns

void void

Example

container.addMetadata({
  requestId: 'req-123',
  userAgent: 'Mozilla/5.0...',
  processingTime: 1500
});

Inherited from

BaseContainer.addMetadata

addTag()

addTag(key, value): void
Defined in: src/lib/logger/components/base.ts:94 Adds a tag to this container for categorization and filtering.

Parameters

key
string The tag key
value
string The tag value

Returns

void void

Example

container.addTag('environment', 'production');
container.addTag('user_type', 'premium');

Inherited from

BaseContainer.addTag

data()

data(): any
Defined in: src/lib/logger/components/error.ts:81 Returns the complete data representation of this error.

Returns

any Error data

Example

const errorData = error.data();

Overrides

BaseContainer.data

end()

end(): void
Defined in: src/lib/logger/components/base.ts:163 Marks this container as ended and records the end timestamp.

Returns

void void

Example

// End a container when processing is complete
container.end();

Inherited from

BaseContainer.end

addMetadata_()

static addMetadata_(writer, entity, id, metadata): void
Defined in: src/lib/logger/components/base.ts:144 Static method to add metadata to any container by ID.

Parameters

writer
LogWriter The log writer instance
entity
Entity The entity type
id
string The container ID
metadata
Record<string, unknown> The metadata to add

Returns

void void

Inherited from

BaseContainer.addMetadata_

addTag_()

static addTag_(writer, entity, id, key, value): void
Defined in: src/lib/logger/components/base.ts:108 Static method to add a tag to any container by ID.

Parameters

writer
LogWriter The log writer instance
entity
Entity The entity type
id
string The container ID
key
string The tag key
value
string The tag value

Returns

void void

Inherited from

BaseContainer.addTag_

end_()

static end_(writer, entity, id, data?): void
Defined in: src/lib/logger/components/base.ts:177 Static method to end any container by ID.

Parameters

writer
LogWriter The log writer instance
entity
Entity The entity type
id
string The container ID
data?
any Optional additional data to include with the end event

Returns

void void

Inherited from

BaseContainer.end_