Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/FarlandsModdingTeam/TerbinProyect/llms.txt

Use this file to discover all available pages before exploring further.

Terbin defines multiple complementary error-code enums, each targeting a different layer of the stack. TerbinErrorCode is the low-level protocol enum serialised over the wire as a ushort. AppError covers higher-level business-logic failures as a long. ErrorFlags and ExceptionFlags are bitflag enums that let you combine multiple simultaneous error conditions into a single value for rich diagnostics. Together they provide a fully typed, code-based error system without relying on string parsing or exception message inspection.

TerbinErrorCode enum (ushort)

TerbinErrorCode is the primary low-level error code type. It costs only 2 bytes on the wire. A value of 0 (None) always means success; every other value indicates a failure in one of the categories below.
public enum TerbinErrorCode : ushort
{
    None = 0, // All good (Success)
    ...
}

Range overview

RangeCategoryRepresentative values
1000–1999ValidationParameterNull, FormatInvalid, ValueOutOfRange
2000–2999ProtocolPacketMalformed, PayloadTooLarge, FragmentationError
3000–3999MemoryMemoryIdNotFound, BufferOverflow, StreamReadError
4000–4999ExecutionActionNotFound, HandlerExecutionFailed, InvalidSignature
5000–5999Business logicResourceNotFound, InvalidStateTransition, OperationCancelled
6000–6999SecurityUnauthorized, ForbiddenAccess, SignatureInvalid
7000–7999ConnectivityTimeoutExceeded, ConnectionLost, EndpointUnreachable
9000–9999FatalInternalSystemError, OutOfMemory, NotImplementedYet

1000–1999: Validation

Errors in this range indicate that input data did not pass basic validation before any protocol or business logic was attempted.
ValueNameDescription
1001ParameterNullA required parameter was null.
1002ParameterEmptyA required parameter was empty (string or collection).
1003FormatInvalidThe value does not match the expected format.
1004ValueOutOfRangeThe value falls outside the permitted range.
1005LengthExceededThe input is longer than the maximum allowed length.
1006MissingRequiredDataA required field or piece of data was not provided.
1007InvalidCastThe value could not be cast to the expected type.
1008DataTypeMismatchThe CodeTypeData encoding does not match the actual payload type.
1009InvalidLengthThe length field contains an invalid value.

2000–2999: Protocol

Errors in this range arise from malformed or out-of-order packets during the Terbin packet exchange.
ValueNameDescription
2001PacketMalformedThe packet structure is corrupt or cannot be parsed.
2002HeaderInvalidThe packet header contains invalid values.
2003PayloadTooLargeThe payload exceeds MAX_PLD (0xFFF0).
2004FragmentationErrorAn error occurred while processing a fragmented (FRAGMENT_IN) packet.
2005PacketOrderMismatchA packet arrived out of the expected sequence order.
2006FinalPacketMissingThe final fragment (FINAL_PACKET = 0xFFFF) was never received.
2007ChecksumInvalidThe packet checksum does not match its contents.
2008ProtocolVersionUnknownThe protocol version in the header is not recognised.
2009AlreadyExistsA packet or petition with this ID already exists in-flight.
2010OverMaximusPacketThe packet count exceeded the protocol maximum.

3000–3999: Memory

Errors in this range originate from the memory-management layer (TerbinMemory, streams, and buffer operations).
ValueNameDescription
3001MemoryIdNotFoundTryGetResult() failed — the memory slot ID does not exist.
3002MemoryReleaseFailedThe memory slot could not be released after use.
3003MemoryStoreFailedStoring data into the memory slot failed.
3004MemoryAlreadyAllocatedThe slot is already allocated; cannot allocate again.
3005BufferOverflowA write operation would overflow the buffer.
3006StreamReadErrorFailed to read bytes from a stream.
3007StreamWriteErrorFailed to write bytes to a stream.
3008ReservedMemoryAccessAttempted to use a slot in the reserved memory range (RESERVE_MEMORY = 9).
3009OrderMismatchFragments arrived in the wrong order during stream reassembly.

4000–4999: Execution

Errors in this range come from the ExecutableDispatcher and action-registration subsystem.
ValueNameDescription
4001ActionNotFoundNo handler is registered for the incoming action key.
4002ActionAlreadyRegisteredAttempted to register a handler for an action that already has one.
4003ActionRegistrationFailedThe registration process itself failed (e.g. reflection error).
4004HandlerExecutionFailedAn exception was caught inside DispatchAsync.
4005InvalidSignatureThe handler method signature does not match the required delegate type.

5000–5999: Business Logic

Domain-level errors that indicate a valid request could not be fulfilled due to state or resource constraints.
ValueNameDescription
5001ResourceNotFoundThe requested business resource does not exist.
5002ResourceAlreadyExistsCannot create a resource that already exists.
5003InvalidStateTransitionThe operation is not permitted in the current state.
5004OperationCancelledThe operation was cancelled before completion.
5005LimitExceededA quota or business-level limit was exceeded.

6000–6999: Security

ValueNameDescription
6001UnauthorizedThe caller is not authenticated.
6002ForbiddenAccessThe caller is authenticated but lacks permission for this action.
6003SignatureInvalidThe cryptographic or HMAC signature on the request is invalid.

7000–7999: Connectivity

ValueNameDescription
7001TimeoutExceededThe operation exceeded MAXIMUS_RESPONSE_TIME (8 seconds).
7002ConnectionLostThe named-pipe or socket connection dropped unexpectedly.
7003EndpointUnreachableThe target endpoint could not be reached.

9000–9999: Fatal

Fatal errors mean the worker cannot continue safely. These should be surfaced as critical alerts.
ValueNameDescription
9000InternalSystemErrorAn unexpected, unrecoverable system-level error occurred.
9001OutOfMemoryThe process ran out of managed or unmanaged memory.
9999NotImplementedYetThe code path has not been implemented yet.

AppError enum (long)

AppError targets higher-level, human-readable business-logic errors. It is a long, making it suitable for in-process error propagation without the two-byte wire constraint of TerbinErrorCode. None = 0 means success.

Range summary

RangeCategory
100–199Validation — parameter and data quality checks
200–299Collections — lookup and list operations
300–399State & business logic — operation legality
400–499Security & permissions
500–599Infrastructure — I/O, network, and concurrency
900–999Critical / uncontrolled errors

Commonly referenced values

ValueNameDescription
100NullValueA null was passed where a value was required.
101EmptyValueAn empty string or collection was passed.
102WhitespaceOnlyA string contained only whitespace.
103ValueTooLowValue is below the minimum (e.g. a negative where positive was required).
104ValueTooHighValue exceeds the maximum.
105LengthTooShortString or collection is shorter than required.
106LengthTooLongString or collection exceeds the maximum length.
107InvalidFormatValue doesn’t match the required format (e.g. regex, email).
108InvalidTypeThe data type is not what was expected.
200ItemNotFoundItem is absent from a dictionary or list.
201ItemAlreadyExistsAttempted to add a duplicate ID.
202CollectionEmptyThe list or collection has no elements to process.
203IndexOutOfRangeArray index is outside valid bounds.
300InvalidStateThe operation is not valid in the current state.
301NotAllowedThe operation is not permitted in this context.
302DependencyMissingA required dependency or precondition is absent.
303LimitExceededA logical quota was exceeded.
304ExpiredA token, session, or datum has expired.
400UnauthorizedCaller is not authenticated.
401ForbiddenCaller is authenticated but not permitted.
402InvalidCredentialsWrong username or password.
500TimeoutThe operation took too long.
501ConnectionFailedNamed-pipe, socket, or other connection failure.
502ResourceLockedA file or memory resource is locked by another thread.
503ReadErrorFailed to read from disk or stream.
504WriteErrorFailed to write to disk or stream.
900NotImplementedThe function has not been programmed yet.
999InternalErrorGeneric unexpected error (“something weird happened”).

ErrorFlags enum (ulong) and ExceptionFlags enum (ulong)

Both ErrorFlags and ExceptionFlags are [Flags] bitflag enums backed by ulong (64 bits), allowing any combination of error conditions to be expressed as a single value. They are intended as a rich diagnostic and future-extension mechanism.
ErrorFlags and ExceptionFlags are provided as a design reference and future extension mechanism. They are not yet heavily used in the current Terbin codebase, but you can use them today for rich in-process error aggregation or logging.
ErrorFlags organises its 64 bits into eight categories. You can OR multiple flags together to express combined failure conditions.
[Flags]
public enum ErrorFlags : ulong { ... }
Validation (bits 0–6)
BitNameDescription
0NullParameterA required parameter was null.
1EmptyStringA required string was empty.
2FormatInvalidValue format is wrong.
3ValueOutOfRangeValue is outside the permitted range.
4InvalidLengthLength field is invalid.
5MissingRequiredDataRequired data was absent.
6InvalidCastA type cast failed.
Protocol & Packets (bits 8–14)
BitNameDescription
8PacketMalformedPacket structure is corrupt.
9HeaderInvalidHeader contains invalid values.
10PayloadTooLargePayload exceeds MAX_PLD.
11FragmentationErrorFragment reassembly failed.
12OrderMismatchUnexpected packet sequence order.
13ChecksumMismatchChecksum does not match.
14UnknownProtocolTypeUnrecognised protocol type byte.
Memory & Streams (bits 16–22)
BitNameDescription
16MemoryNotAllocatedMemory slot was never allocated.
17MemoryIdNotFoundRelease() or TryGetResult() failed to find the slot.
18BufferOverflowWrite would overflow the buffer.
19StreamReadErrorRead from stream failed.
20StreamWriteErrorWrite to stream failed.
21EndOfStreamReachedUnexpected end of stream.
22MemoryCorruptedMemory contents are corrupt.
Execution & Dispatching (bits 24–28)
BitNameDescription
24ActionNotFoundNo handler registered for action key.
25HandlerNotSetHandler delegate is null.
26MethodMismatchHandler method signature doesn’t match.
27ExecutionFaultGeneric catch in DispatchAsync triggered.
28ActionAlreadyExistsDuplicate action registration attempted.
State & Business Logic (bits 32–38)
BitNameDescription
32NotFoundResource not found.
33AlreadyExistsResource already exists.
34InvalidStateInvalid state transition.
35LimitExceededQuota or business limit exceeded.
36DuplicateRequestDuplicate in-flight request.
37NotImplementedYetFeature not yet implemented.
38OperationRejectedOperation explicitly rejected.
Security (bits 42–45)
BitNameDescription
42UnauthorizedNot authenticated.
43ForbiddenAuthenticated but not permitted.
44TokenExpiredAuthentication token has expired.
45SignatureInvalidCryptographic signature is invalid.
Connectivity & Concurrency (bits 48–53)
BitNameDescription
48TimeoutExceeded MAXIMUS_RESPONSE_TIME.
49ResourceLockedFile or memory is locked by another thread.
50NetworkUnavailableNetwork is not available.
51ConnectionLostConnection dropped unexpectedly.
52UserCancelledUser explicitly cancelled the operation.
53RateLimitedRequest was rate-limited.
Critical Infrastructure (bits 56–63)
BitNameDescription
56InternalSystemErrorUnrecoverable system error.
57DiskWriteFailedWrite to disk failed.
58DataCorruptedStored data is corrupt.
63FatalErrorHighest-bit fatal sentinel — unrecoverable.
ExceptionFlags mirrors the .NET exception type hierarchy as bit flags. Each bit represents a specific exception class, allowing exception sets to be captured and compared without holding live exception objects.
[Flags]
public enum ExceptionFlags : ulong { ... }
Base & Runtime (bits 0–7)
BitName
0Exception
1SystemException
2ApplicationException
3NullReferenceException
4InvalidOperationException
5NotImplementedException
6NotSupportedException
7PlatformNotSupportedException
Arguments (bits 8–10)
BitName
8ArgumentException
9ArgumentNullException
10ArgumentOutOfRangeException
Memory & Fatal Execution (bits 11–14)
BitName
11OutOfMemoryException
12StackOverflowException
13ExecutionEngineException
14AccessViolationException
Math & Types (bits 15–20)
BitName
15DivideByZeroException
16OverflowException
17ArithmeticException
18FormatException
19InvalidCastException
20IndexOutOfRangeException
Tasks & Threading (bits 21–27)
BitName
21TimeoutException
22OperationCanceledException
23TaskCanceledException
24AggregateException
25ThreadAbortException
26ThreadInterruptedException
27ThreadStateException
Files & I/O (bits 28–33)
BitName
28IOException
29FileNotFoundException
30DirectoryNotFoundException
31PathTooLongException
32EndOfStreamException
33InvalidDataException
Network & Web (bits 34–36)
BitName
34SocketException
35HttpRequestException
36WebException
Database & Data (bits 37–39)
BitName
37DataException
38DBConcurrencyException
39SqlException
Security & Access (bits 40–42)
BitName
40UnauthorizedAccessException
41SecurityException
42CryptographicException
Collections (bits 43–45)
BitName
43KeyNotFoundException
44RankException
45ArrayTypeMismatchException
Serialization & Formats (bits 46–48)
BitName
46SerializationException
47XmlException
48JsonException
Reflection & Type Loading (bits 49–55)
BitName
49TypeInitializationException
50TypeLoadException
51MissingMemberException
52MissingFieldException
53MissingMethodException
54AmbiguousMatchException
55BadImageFormatException
Low-level & Rare (bits 56–63)
BitName
56InvalidProgramException
57AppDomainUnloadedException
58CannotUnloadAppDomainException
59ContextMarshalException
60DuplicateWaitObjectException
61FieldAccessException
62MethodAccessException
63DataMisalignedException

Combining flags — example

// Build a combined error flag for diagnostics
ErrorFlags diagnostics = ErrorFlags.NullParameter | ErrorFlags.MissingRequiredData;

if (diagnostics.HasFlag(ErrorFlags.NullParameter))
    Console.WriteLine("Null parameter detected.");

// Capture exception type metadata without holding the exception
ExceptionFlags captured = ExceptionFlags.None;
try { /* ... */ }
catch (FileNotFoundException) { captured |= ExceptionFlags.FileNotFoundException; }
catch (IOException)           { captured |= ExceptionFlags.IOException; }

Console.WriteLine($"Exceptions seen: {captured}");

Build docs developers (and LLMs) love