Skip to content

Releases: ybabts/EAV

1.0.1 Fixes non Discriminating Errors

07 Jul 23:18
Compare
Choose a tag to compare

This release fixes an issue with how isErr was discriminating between Error types and the value of the Result type. Typescript effectively saw any object with the name and message property to be an Error type rather than the value of the Result type. To fix this, a symbol has been added to the global namespace of the Error interface. This allows all types to be discriminated from types that extend from the Error type.

Full Changelog: 1.0.0...1.0.1

1.0.0 Official Release

07 Jul 20:16
Compare
Choose a tag to compare

Errors as Values Official Release

This release adds JSDocs, updates the README to fit the latest API changes, and fixes many incorrect type annotations.

Full Changelog: 0.1.1...1.0.0

0.1.1 CaptureErr API change and isErr bug fix

22 Jun 01:29
Compare
Choose a tag to compare

This release contains an API change to CaptureError as well as a bug fix for isErr.

  • CaptureError has changed from accepting a function and an optional name, returning a "safe" version of the function to accepting a name and function, returning a Result. This leads to more readable code and a very minor increase in performance.
  • isErr's specific error testing functionality did not work with the new error chaining method implemented in the previous version. That has been fixed and now isErr checks every error name in the chain. Please do not make circular references in Error chains and cause an infinite loop.

Please refer to the commit history for more detailed information about each change.

Full Changelog: 0.1.0...0.1.1

0.1.0

19 Jun 02:02
Compare
Choose a tag to compare

This release includes several enhancements and fixes:

  • Refactored and changed a significant amount of code for better readability (#7e77752).
  • Added Promise<Err<N>> to the typing of CaptureErr for improved error handling (#7af94e2).
  • Introduced error chaining to CaptureError for more efficient error propagation (#7461698).
  • Fixed an issue where IgnoreErr was not working with result (#966aedb).
  • Added examples to the table of contents in the README for easier navigation and added many sections to the README (#4b1bf77).

Please refer to the commit history for more detailed information about each change.

Full Changelog: 0.0.2...0.1.0

0.0.2 Type System Improvements

17 Jun 02:52
Compare
Choose a tag to compare

Overview

This release changes a lot with how Typescript's type system interacts with the already existing functions. Much work has been done to make sure that Typescript knows when and what errors exist on a particular value and allow for proper narrowing with isErr. This also introduces a new concept of causality. Every error has a cause property on it that identifies it as an error of a particular type. This is compatible with numbers and strings, which makes using enums possible to both identify and reuse identifying causes for errors in a function.

Changelog:

  1. Linting Rule Change: The updated code now includes a directive to ignore the "no-explicit-any" linting rule for the entire file.

  2. Type Changes:

    • The Result type now includes CustomError as a possible error type.
    • The CustomError type has been expanded to include a cause property of type C which extends ValidCause, and a message property of type M which extends string.
  3. Function Changes:

    • The addMsg function now checks if the error message length is less than or equal to 0 before assigning the message.
    • The Err function now accepts a cause argument and an optional message argument, and returns a CustomError with these properties.
    • The Try function now accepts an optional cause argument and returns a CustomError with this cause if an error is thrown.
    • The isErr function now accepts an optional cause argument and checks if the value's cause matches this cause when determining if the value is an error.
    • The Ok function now returns Exclude<T, Error> instead of T, excluding Error from the possible return types.
  4. New Types and Functions:

    • A new type ValidCause has been introduced, which can be a string or number.
    • A new type ExtractCause has been introduced, which extracts the cause property from a given type.
    • A new function addMsg has been introduced, which adds a message to an error and returns a CustomError.

Example

enum DatabaseErrorCause {
  NotFound = 'NOT_FOUND',
  ConnectionError = 'CONNECTION_ERROR',
  UnexpectedError = 'UNEXPECTED_ERROR',
}

type DatabaseError = CustomError<DatabaseErrorCause, string>;

function fetchUserData(id: string): Result<UserData, DatabaseError> {
  // ... fetch user data from database
  // If an error occurs, return a CustomError with a specific cause
  if (error) {
    return Err(DatabaseErrorCause.NotFound, `User with id ${id} not found.`);
  }
  // If everything is fine, return the user data
  return userData;
}

const result = fetchUserData('123');

const errorMessages = {
  [DatabaseErrorCause.NotFound]: 'User not found. Please check the id.',
  [DatabaseErrorCause.ConnectionError]: 'Could not connect to the database. Please check your connection.',
  [DatabaseErrorCause.UnexpectedError]: 'An unexpected error occurred.',
};

if (isErr(result)) {
  console.log(errorMessages[result.cause]);
} else {
  console.log('User data:', result);
}

Full Changelog: 0.0.1...0.0.2

0.0.1 Initial Release

16 Jun 06:29
Compare
Choose a tag to compare

This the first release of the Errors as Values package, designed to help you incorporate EAV principles into your code.