From 92f11823a1f1e5303731ad9b13cea9d9915a1720 Mon Sep 17 00:00:00 2001 From: INeedJobToStartWork Date: Mon, 25 Nov 2024 21:05:02 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9A=99=EF=B8=8F=20=20Chore(oh-my-error):=20a?= =?UTF-8?q?ddpublish=20config=20to=20package.json?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 69 +++++++++++++++---------------- packages/oh-my-error/package.json | 3 ++ 2 files changed, 36 insertions(+), 36 deletions(-) diff --git a/README.md b/README.md index c6f2ea7..be77ff4 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ ![image](https://github.com/INeedJobToStartWork/MyError/assets/97305201/03fa3e50-af28-4345-a3f7-f84d091b4eb1)

MyError

-

πŸŽ‰2.0.0.prerelease.3🎊

+

πŸŽ‰2.0.0🎊

A Very Clean Error Handler!

πŸ“—Tutorials | @@ -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 @@ -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"] }); @@ -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 @@ -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!"); }); ``` @@ -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)(); ``` @@ -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; ``` diff --git a/packages/oh-my-error/package.json b/packages/oh-my-error/package.json index 84d8554..beb22be 100644 --- a/packages/oh-my-error/package.json +++ b/packages/oh-my-error/package.json @@ -69,5 +69,8 @@ "packageManager": "pnpm@9.4.0", "engines": { "node": ">=20" + }, + "publishConfig": { + "access": "public" } }