Skip to content

Commit

Permalink
🎉 Feat(oh-my-error)!: Realise 2.0.0 version!
Browse files Browse the repository at this point in the history
  • Loading branch information
INeedJobToStartWork committed Nov 25, 2024
1 parent a8dce84 commit 41a4828
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 61 deletions.
8 changes: 0 additions & 8 deletions .changeset/honest-jeans-own.md

This file was deleted.

8 changes: 0 additions & 8 deletions .changeset/pre.json

This file was deleted.

7 changes: 0 additions & 7 deletions .changeset/short-eels-sparkle.md

This file was deleted.

33 changes: 33 additions & 0 deletions packages/oh-my-error/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,38 @@
# oh-my-error

## 2.0.0

### Major Changes

- 4c9780c: - Add type `StatusCode`
- Add missing TSDocs
- Change enum StatusCode to object
- 4f04fe2: - Add new Error Types, New Functions and Features to current existing functions
- Add `statusCodes` enum.
- Refactored `MyError` => `myError`, currently it's error object handler before throw.
- Added new Feature to `myErrorWrapper` - Instant throw error, no need to use condition with `isError` to throw Error.
- Added `myErrorWrapperAsync` which is `myErrorWrapper` alternative for async functions.
- Refactored `TMyError` - renamed `TMyError` => `IMyError`, changed from `type` to `interface` and structure.
- Add new Error (Organism) Interfaces `IMyError`,`IMyErrorAPI`,`IMyErrorRateLimit`,`IMyErrorValidation`
- Add new Error (Atom) types
`TSeverity`,`TSeverity2`,`TErrorMessages`,`TErrorMessagesExt`,`TMyErrorList`,`TErrorList`,`TCauseError`,`TDetails`,`TBaseError`,`TBaseErrorExt`,`TValidationError`,`TApiError`,`TApiRateLimit`,

### Minor Changes

- b9d8ffa: - Add passing Throwed Error to our error at `myErrorWrapper`
- Add types `TValueOrFunctionAll` and `TValueOrFunction`
- Add missing TSDocs to types
- Change myErrorHandler arg[0] type (added unknown)
- 12098d8: - Add new Error Types, New Functions and Features to current existing functions
- `myErrorWrapperAsync` implemented to current `myErrorWrapper`
- `myErrorWrapperAsync` removed

### Patch Changes

- 4c9780c: - Add type `StatusCode`
- Add missing TSDocs
- Change enum StatusCode to object

## 2.0.0-prerelease.3

### Minor Changes
Expand Down
69 changes: 33 additions & 36 deletions packages/oh-my-error/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
![image](https://github.com/INeedJobToStartWork/MyError/assets/97305201/03fa3e50-af28-4345-a3f7-f84d091b4eb1)

<h1 align="center">MyError</h1>
<p align="center"><code>🎉2.0.0.prerelease.3🎊</code></p>
<p align="center"><code>🎉2.0.0🎊</code></p>
<p align="center"><b>A Very Clean Error Handler!</b></p>
<div align="center">
<a href="https://github.com/INeedJobToStartWork/MyError/tree/main/tutorials/README.md">📗Tutorials</a> |
Expand Down Expand Up @@ -35,9 +35,9 @@ What you get:
// Instead
let data;
try {
data = readFile("...path");
data = readFile("...path");
} catch {
throw Error("Cant Load File!");
throw Error("Cant Load File!");
}

// Do
Expand Down Expand Up @@ -116,11 +116,11 @@ Processes an error object, invoking functions with provided arguments

```ts
const MyErrorList = {
BLACKLISTED: {
name: "Black Listed Name",
hint: "Try use other one!",
message: (name: string) => `${name} is on black list!`,
},
BLACKLISTED: {
name: "Black Listed Name",
hint: "Try use other one!",
message: (name: string) => `${name} is on black list!`
}
} as const satisfies TMyErrorList;

throw new myError(MyErrorList.BLACKLISTED, { message: ["nameInputed"] });
Expand Down Expand Up @@ -164,10 +164,7 @@ const data = myErrorWrapper(readFile,err => new Error(`ERROR MESSAGE: ${err.mess
> At async function it returns Promise, just use `await` to solve that
```ts
const data = await myErrorWrapper(
asyncFun,
new Error("Oh, Error!")
)("MyString");
const data = await myErrorWrapper(asyncFun, new Error("Oh, Error!"))("MyString");
```

### myErrorCatcher
Expand All @@ -176,8 +173,8 @@ const data = await myErrorWrapper(

```ts
const data = await myErrorCatcher(readFile)("path...").catch(() => {
// Code before crash...
throw new Error("Can't read file!");
// Code before crash...
throw new Error("Can't read file!");
});
```

Expand All @@ -189,10 +186,10 @@ Execute Scenarios for an error!
const [data, isError] = myErrorWrapper(readFile)("./ReadThisFile");

const MyErrorHandlerList = {
FS001: () => {
// Do this code if throw this error
console.error("ERROR");
},
FS001: () => {
// Do this code if throw this error
console.error("ERROR");
}
};
if (isError) myErrorHandler(data.code, MyErrorHandlerList)();
```
Expand All @@ -211,24 +208,24 @@ if (isError) myErrorHandler(data.code, MyErrorHandlerList)();
```ts
const ErrorList = {
notFound: {
name: "Not Found",
code: "FS001",
message: {
user: "File not found",
dev: "The file you are trying to read does not exist",
},
hint: (path: string) => `Check if the file exists at ${path}`,
} satisfies IMyError,
cantRead: {
code: "FS002",
name: "Cant Read",
message: { user: "Can't read file", dev: "readFileSync throw error" },
hint: {
user: "Check if the file is not corrupted or permissions",
dev: "File is corrupted or has no permissions to be read",
},
},
notFound: {
name: "Not Found",
code: "FS001",
message: {
user: "File not found",
dev: "The file you are trying to read does not exist"
},
hint: (path: string) => `Check if the file exists at ${path}`
} satisfies IMyError,
cantRead: {
code: "FS002",
name: "Cant Read",
message: { user: "Can't read file", dev: "readFileSync throw error" },
hint: {
user: "Check if the file is not corrupted or permissions",
dev: "File is corrupted or has no permissions to be read"
}
}
} as const satisfies TMyErrorList;
```

Expand Down
2 changes: 1 addition & 1 deletion packages/oh-my-error/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "oh-my-error",
"version": "2.0.0-prerelease.3",
"version": "2.0.0",
"description": "A simple error handler for nodejs",
"keywords": [
"error",
Expand Down
9 changes: 9 additions & 0 deletions tutorials/EveryThingAbout/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# @tutorial/alex-story

## 1.0.1

### Patch Changes

- Updated dependencies [b9d8ffa]
- Updated dependencies [4c9780c]
- [email protected]
2 changes: 1 addition & 1 deletion tutorials/EveryThingAbout/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tutorial/alex-story",
"version": "1.0.0",
"version": "1.0.1",
"description": "",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 41a4828

Please sign in to comment.