Skip to content

Commit

Permalink
⚙️ Chore(oh-my-error): addpublish config to package.json
Browse files Browse the repository at this point in the history
  • Loading branch information
INeedJobToStartWork committed Nov 25, 2024
1 parent 3d01d0c commit 92f1182
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 36 deletions.
69 changes: 33 additions & 36 deletions 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
3 changes: 3 additions & 0 deletions packages/oh-my-error/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,8 @@
"packageManager": "[email protected]",
"engines": {
"node": ">=20"
},
"publishConfig": {
"access": "public"
}
}

0 comments on commit 92f1182

Please sign in to comment.