Skip to main content

errors.go

Filename: errors.go

  1. Overview

This file defines a set of standard error variables and functions for the DiceDB project. It aims to provide consistent error handling and messaging throughout the application.

  1. Detailed Documentation

Constants

  • ArityErr: String representing an arity error message.
  • SyntaxErr: String representing a syntax error message.
  • ExpiryErr: String representing an invalid expire time error message.
  • IntOrOutOfRangeErr: String representing an integer out of range error message.
  • IntOrFloatErr: String representing a value that is not an integer or a float.
  • ValOutOfRangeErr: String representing a value out of range.
  • IncrDecrOverflowErr: String representing an increment/decrement overflow error message.
  • NoKeyErr: String representing a "no such key" error message.
  • ErrDefault: String representing the default error format.
  • WrongTypeErr: String representing a wrong type operation error message.
  • WrongTypeHllErr: String representing a wrong type HyperLogLog error message.
  • InvalidHllErr: String representing an invalid HyperLogLog object error message.
  • CmdHandlerNotFoundErr: String representing a command handler not found error message.
  • JSONPathValueTypeErr: String representing a JSON path value type error message.
  • HashValueNotIntegerErr: String representing a hash value not an integer error message.
  • InternalServerError: String representing a generic internal server error.
  • InvalidFloatErr: String representing an invalid float error.
  • InvalidIntErr: String representing an invalid integer error.
  • InvalidBitfieldType: String representing an invalid bitfield type error.
  • BitfieldOffsetErr: String representing a bitfield offset error.
  • OverflowTypeErr: String representing an invalid overflow type error.
  • WrongKeyTypeErr: String representing a wrong key type error.
  • NoKeyExistsErr: String representing that a key does not exist.

Variables

  • ErrAuthFailed: Error indicating authentication failure.
  • ErrIntegerOutOfRange: Error indicating that an integer is out of range.
  • ErrInvalidNumberFormat: Error indicating an invalid number format.
  • ErrValueOutOfRange: Error indicating a value is out of range.
  • ErrOverflow: Error indicating an overflow.
  • ErrKeyNotFound: Error indicating that a key was not found.
  • ErrWrongTypeOperation: Error indicating a wrong type operation.
  • ErrInvalidHyperLogLogKey: Error indicating an invalid HyperLogLog key.
  • ErrCorruptedHyperLogLogObject: Error indicating a corrupted HyperLogLog object.
  • ErrInvalidJSONPathType: Error indicating an invalid JSON path type.
  • ErrHashValueNotInteger: Error indicating a hash value that is not an integer.
  • ErrInternalServer: Error indicating an internal server error.
  • ErrAuth: Error indicating missing password configuration.
  • ErrAborted: Error indicating the server received an ABORT command.
  • ErrEmptyCommand: Error indicating an empty command.
  • ErrInvalidIPAddress: Error indicating an invalid IP address.
  • ErrInvalidFingerprint: Error indicating an invalid fingerprint.
  • ErrKeyDoesNotExist: Error indicating an operation on a non-existent key.
  • ErrKeyExists: Error indicating that a key already exists.
  • ErrUnknownObjectType: Error indicating an unknown object type.

Functions

  • ErrInvalidValue(command string, param string) error:

    • Purpose: Returns a formatted error indicating an invalid value for a parameter in a given command.
    • Parameters:
      • command (string): The name of the command.
      • param (string): The name of the parameter.
    • Returns: error: A formatted error message.
  • ErrInvalidSyntax(command string) error:

    • Purpose: Returns a formatted error indicating invalid syntax for a given command.
    • Parameters:
      • command (string): The name of the command.
    • Returns: error: A formatted error message.
  • ErrWrongArgumentCount(command string) error:

    • Purpose: Returns a formatted error indicating the wrong number of arguments for a given command.
    • Parameters:
      • command (string): The name of the command.
    • Returns: error: A formatted error message.
  • ErrInvalidExpireTime(command string) error:

    • Purpose: Returns a formatted error indicating an invalid expire time for a given command.
    • Parameters:
      • command (string): The name of the command.
    • Returns: error: A formatted error message.
  • ErrInvalidElementPeekCount(max int) error:

    • Purpose: Returns a formatted error indicating the number of elements to peek is invalid.
    • Parameters:
      • max (int): The maximum number of elements allowed.
    • Returns: error: A formatted error message.
  • ErrGeneral(err string) error:

    • Purpose: Returns a general error with the given message.
    • Parameters:
      • err (string): The error message.
    • Returns: error: An error with the given message.
  • ErrFormatted(errMsg string, opts ...any) error:

    • Purpose: Returns a formatted error using fmt.Sprintf.
    • Parameters:
      • errMsg (string): The error message format string.
      • opts (...any): The arguments to the format string.
    • Returns: error: A formatted error.
  • ErrIOThreadNotFound(id string) error:

    • Purpose: Returns a formatted error indicating that an io-thread with the specified ID was not found.
    • Parameters:
      • id (string): The ID of the io-thread.
    • Returns: error: A formatted error message.
  • ErrJSONPathNotFound(path string) error:

    • Purpose: Returns a formatted error indicating that a JSON path was not found.
    • Parameters:
      • path (string): The JSON path.
    • Returns: error: A formatted error message.
  • ErrUnsupportedEncoding(encoding int) error:

    • Purpose: Returns a formatted error indicating an unsupported encoding type.
    • Parameters:
      • encoding (int): The encoding type.
    • Returns: error: A formatted error message.
  • ErrUnexpectedType(expectedType string, actualType interface{}) error:

    • Purpose: Returns a formatted error indicating an unexpected type.
    • Parameters:
      • expectedType (string): The expected type.
      • actualType (interface<>): The actual type.
    • Returns: error: A formatted error message.
  • ErrUnexpectedJSONPathType(expectedType string, actualType interface{}) error:

    • Purpose: Returns a formatted error indicating an unexpected JSON path type.
    • Parameters:
      • expectedType (string): The expected type.
      • actualType (interface<>): The actual type.
    • Returns: error: A formatted error message.
  • ErrUnknownCmd(cmd string) error:

    • Purpose: Returns a formatted error indicating an unknown command.
    • Parameters:
      • cmd (string): The command name.
    • Returns: error: A formatted error message.

Types

  • PreProcessError struct:

    • Purpose: Represents an error that occurs during pre-processing.

    • Fields:

      • Result (interface<>): The result of the pre-processing, potentially containing error information.
    • (e *PreProcessError) Error() string:

      • Purpose: Returns the string representation of the Result field.
      • Returns: string: The string representation of the Result.
  • DiceError struct:

    • Purpose: Represents a DiceDB-specific error.

    • Fields:

      • message (error): The underlying error message.
    • newDiceErr(message string) *DiceError:

      • Purpose: Creates a new DiceError instance.
      • Parameters:
        • message (string): The error message.
      • Returns: *DiceError: A pointer to the new DiceError instance.
    • (d *DiceError) toEncodedMessage() []byte:

      • Purpose: Encodes the error message into a byte slice with a newline character.
      • Returns: []byte: The encoded error message.

Functions

  • NewErr(message string) error:

    • Purpose: Creates a new error with the given message.
    • Parameters:
      • message (string): The error message.
    • Returns: error: A new error.
  • NewErrWithMessage(errMsg string) []byte:

    • Purpose: Creates a new error message, prepending "-ERR " if the message doesn't already start with an error code.
    • Parameters:
      • errMsg (string): The error message.
    • Returns: []byte: The encoded error message.
  • NewErrWithFormattedMessage(errMsgFmt string, args ...interface{}) []byte:

    • Purpose: Creates a new error message with formatting.
    • Parameters:
      • errMsgFmt (string): The format string for the error message.
      • args (...interface<>): The arguments to the format string.
    • Returns: []byte: The encoded error message.
  • NewErrArity(cmdName string) []byte:

    • Purpose: Creates a new arity error message for a given command name.
    • Parameters:
      • cmdName (string): The name of the command.
    • Returns: []byte: The encoded arity error message.
  • NewErrExpireTime(cmdName string) []byte:

    • Purpose: Creates a new expire time error message for a given command name.
    • Parameters:
      • cmdName (string): The name of the command.
    • Returns: []byte: The encoded expire time error message.
  1. Code Examples
// Example of creating a simple error
const err = NewErr("Something went wrong");
console.log(err.Error()); // Output: Something went wrong

// Example of creating a formatted error message
const formattedErr = NewErrWithFormattedMessage("Invalid value: %s", "test");
console.log(String.fromCharCode(...formattedErr)); //example output: -ERR Invalid value: test

  1. Getting Started Relevance