From 241f767714274f0c604de812be8888614bec4ccf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Lenon?= Date: Wed, 27 Apr 2022 18:19:00 -0300 Subject: [PATCH] feat(exception): paint message and help values in pretiffy --- index.d.ts | 11 ++++++++++- index.js | 2 +- package.json | 2 +- src/Clean.js | 2 +- src/Config.js | 2 +- src/Debug.js | 2 +- src/Exception.js | 13 +++++++++++-- src/Exceptions/ConfigNotNormalizedException.js | 2 +- src/Exceptions/InvalidNumberException.js | 2 +- src/Exceptions/InvalidUuidException.js | 2 +- src/Exceptions/NodeExecException.js | 2 +- src/Exceptions/NotFoundFileException.js | 2 +- src/Exceptions/NotFoundFolderException.js | 2 +- src/Exceptions/OrdinalNanException.js | 2 +- src/Exceptions/RecursiveConfigException.js | 2 +- src/Exceptions/RouteMatchException.js | 2 +- src/Exec.js | 3 ++- src/File.js | 2 +- src/Folder.js | 2 +- src/Is.js | 2 +- src/Json.js | 2 +- src/Number.js | 2 +- src/Options.js | 2 +- src/Parser.js | 2 +- src/Path.js | 2 +- src/Route.js | 2 +- src/String.js | 2 +- src/Uuid.js | 2 +- tests/Stubs/config/app.js | 2 +- tests/Stubs/config/database.js | 2 +- tests/Stubs/config/notNormalized.js | 2 +- tests/Stubs/config/recursiveOne.js | 2 +- tests/Stubs/config/recursiveTwo.js | 2 +- tests/Unit/CleanTest.js | 2 +- tests/Unit/ConfigTest.js | 2 +- tests/Unit/DebugTest.js | 2 +- tests/Unit/ExceptionTest.js | 2 +- tests/Unit/ExecTest.js | 2 +- tests/Unit/FileTest.js | 2 +- tests/Unit/FolderTest.js | 2 +- tests/Unit/IsTest.js | 2 +- tests/Unit/JsonTest.js | 2 +- tests/Unit/NumberTest.js | 2 +- tests/Unit/ParserTest.js | 2 +- tests/Unit/PathTest.js | 2 +- tests/Unit/RouteTest.js | 2 +- tests/Unit/StringTest.js | 2 +- tests/Unit/UuidTest.js | 2 +- 48 files changed, 68 insertions(+), 49 deletions(-) diff --git a/index.d.ts b/index.d.ts index a212c95..bafde8c 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,3 +1,12 @@ +/** + * @secjs/utils + * + * (c) João Lenon + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + export declare interface ExceptionJSON { code?: string name: string @@ -115,7 +124,7 @@ export declare class Debug { export declare class Exception extends Error { constructor(content?: string, status?: number, code?: string, help?: string) - toJSON(stack: boolean): ExceptionJSON + toJSON(stack?: boolean): ExceptionJSON prettify(options?: { prefix?: string diff --git a/index.js b/index.js index fa2821f..fb8f04a 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,5 @@ /** - * @secjs/esm + * @secjs/utils * * (c) João Lenon * diff --git a/package.json b/package.json index 40b3f78..ed6e1fd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@secjs/utils", - "version": "1.8.4", + "version": "1.8.5", "description": "Utils functions and classes for Node.js", "license": "MIT", "author": "João Lenon ", diff --git a/src/Clean.js b/src/Clean.js index aa6d405..0a7cef4 100644 --- a/src/Clean.js +++ b/src/Clean.js @@ -1,5 +1,5 @@ /** - * @secjs/esm + * @secjs/utils * * (c) João Lenon * diff --git a/src/Config.js b/src/Config.js index 510fbfd..6047841 100644 --- a/src/Config.js +++ b/src/Config.js @@ -1,5 +1,5 @@ /** - * @secjs/esm + * @secjs/utils * * (c) João Lenon * diff --git a/src/Debug.js b/src/Debug.js index 99d475f..304508c 100644 --- a/src/Debug.js +++ b/src/Debug.js @@ -1,5 +1,5 @@ /** - * @secjs/esm + * @secjs/utils * * (c) João Lenon * diff --git a/src/Exception.js b/src/Exception.js index 09d084e..9f10c96 100644 --- a/src/Exception.js +++ b/src/Exception.js @@ -1,5 +1,5 @@ /** - * @secjs/esm + * @secjs/utils * * (c) João Lenon * @@ -8,6 +8,7 @@ */ import Youch from 'youch' +import chalk from 'chalk' import changeCase from 'change-case' import YouchTerminal from 'youch-terminal' @@ -113,8 +114,16 @@ export class Exception extends Error { displayMainFrameOnly: false, }) + const message = `${chalk.yellow.bold('MESSAGE')}\n ${this.message}` + const help = ` ${chalk.green.bold('HELP')}\n ${this.help}` + this.name = this.code - this.message = `Message: ${this.message}\n Help: ${this.help}` + + if (this.help) { + this.message = `${message}\n\n${help}` + } else { + this.message = `${message}` + } const jsonResponse = await new Youch(this, {}).toJSON() diff --git a/src/Exceptions/ConfigNotNormalizedException.js b/src/Exceptions/ConfigNotNormalizedException.js index 9a6dc72..3752eb1 100644 --- a/src/Exceptions/ConfigNotNormalizedException.js +++ b/src/Exceptions/ConfigNotNormalizedException.js @@ -1,5 +1,5 @@ /** - * @secjs/esm + * @secjs/utils * * (c) João Lenon * diff --git a/src/Exceptions/InvalidNumberException.js b/src/Exceptions/InvalidNumberException.js index 8bd089d..82c785b 100644 --- a/src/Exceptions/InvalidNumberException.js +++ b/src/Exceptions/InvalidNumberException.js @@ -1,5 +1,5 @@ /** - * @secjs/esm + * @secjs/utils * * (c) João Lenon * diff --git a/src/Exceptions/InvalidUuidException.js b/src/Exceptions/InvalidUuidException.js index 1741d49..1e72caa 100644 --- a/src/Exceptions/InvalidUuidException.js +++ b/src/Exceptions/InvalidUuidException.js @@ -1,5 +1,5 @@ /** - * @secjs/esm + * @secjs/utils * * (c) João Lenon * diff --git a/src/Exceptions/NodeExecException.js b/src/Exceptions/NodeExecException.js index f53417f..b4b88fb 100644 --- a/src/Exceptions/NodeExecException.js +++ b/src/Exceptions/NodeExecException.js @@ -1,5 +1,5 @@ /** - * @secjs/esm + * @secjs/utils * * (c) João Lenon * diff --git a/src/Exceptions/NotFoundFileException.js b/src/Exceptions/NotFoundFileException.js index c5e8992..c74748f 100644 --- a/src/Exceptions/NotFoundFileException.js +++ b/src/Exceptions/NotFoundFileException.js @@ -1,5 +1,5 @@ /** - * @secjs/esm + * @secjs/utils * * (c) João Lenon * diff --git a/src/Exceptions/NotFoundFolderException.js b/src/Exceptions/NotFoundFolderException.js index 36bcf85..27f6238 100644 --- a/src/Exceptions/NotFoundFolderException.js +++ b/src/Exceptions/NotFoundFolderException.js @@ -1,5 +1,5 @@ /** - * @secjs/esm + * @secjs/utils * * (c) João Lenon * diff --git a/src/Exceptions/OrdinalNanException.js b/src/Exceptions/OrdinalNanException.js index f36bd8c..6d4c7a5 100644 --- a/src/Exceptions/OrdinalNanException.js +++ b/src/Exceptions/OrdinalNanException.js @@ -1,5 +1,5 @@ /** - * @secjs/esm + * @secjs/utils * * (c) João Lenon * diff --git a/src/Exceptions/RecursiveConfigException.js b/src/Exceptions/RecursiveConfigException.js index 03ad6e5..0c71a4e 100644 --- a/src/Exceptions/RecursiveConfigException.js +++ b/src/Exceptions/RecursiveConfigException.js @@ -1,5 +1,5 @@ /** - * @secjs/esm + * @secjs/utils * * (c) João Lenon * diff --git a/src/Exceptions/RouteMatchException.js b/src/Exceptions/RouteMatchException.js index 170fa50..469d806 100644 --- a/src/Exceptions/RouteMatchException.js +++ b/src/Exceptions/RouteMatchException.js @@ -1,5 +1,5 @@ /** - * @secjs/esm + * @secjs/utils * * (c) João Lenon * diff --git a/src/Exec.js b/src/Exec.js index c20e0ad..a512f9a 100644 --- a/src/Exec.js +++ b/src/Exec.js @@ -1,5 +1,5 @@ /** - * @secjs/esm + * @secjs/utils * * (c) João Lenon * @@ -12,6 +12,7 @@ import { Transform } from 'node:stream' import { request as requestHttp } from 'node:http' import { request as requestHttps } from 'node:https' import { exec as childProcessExec } from 'node:child_process' + import { File } from '#src/File' import { Options } from '#src/Options' import { NodeExecException } from '#src/Exceptions/NodeExecException' diff --git a/src/File.js b/src/File.js index d737c9b..90f8ed2 100644 --- a/src/File.js +++ b/src/File.js @@ -1,5 +1,5 @@ /** - * @secjs/esm + * @secjs/utils * * (c) João Lenon * diff --git a/src/Folder.js b/src/Folder.js index 6842411..f9078f0 100644 --- a/src/Folder.js +++ b/src/Folder.js @@ -1,5 +1,5 @@ /** - * @secjs/esm + * @secjs/utils * * (c) João Lenon * diff --git a/src/Is.js b/src/Is.js index e26c573..669c3ea 100644 --- a/src/Is.js +++ b/src/Is.js @@ -1,5 +1,5 @@ /** - * @secjs/esm + * @secjs/utils * * (c) João Lenon * diff --git a/src/Json.js b/src/Json.js index 5ec7b67..3b0ff05 100644 --- a/src/Json.js +++ b/src/Json.js @@ -1,5 +1,5 @@ /** - * @secjs/esm + * @secjs/utils * * (c) João Lenon * diff --git a/src/Number.js b/src/Number.js index 2468d87..c9a5067 100644 --- a/src/Number.js +++ b/src/Number.js @@ -1,5 +1,5 @@ /** - * @secjs/esm + * @secjs/utils * * (c) João Lenon * diff --git a/src/Options.js b/src/Options.js index 75f17a1..19be0e9 100644 --- a/src/Options.js +++ b/src/Options.js @@ -1,5 +1,5 @@ /** - * @secjs/esm + * @secjs/utils * * (c) João Lenon * diff --git a/src/Parser.js b/src/Parser.js index 2cc0981..6975af0 100644 --- a/src/Parser.js +++ b/src/Parser.js @@ -1,5 +1,5 @@ /** - * @secjs/esm + * @secjs/utils * * (c) João Lenon * diff --git a/src/Path.js b/src/Path.js index ca5747d..424ea6d 100644 --- a/src/Path.js +++ b/src/Path.js @@ -1,5 +1,5 @@ /** - * @secjs/esm + * @secjs/utils * * (c) João Lenon * diff --git a/src/Route.js b/src/Route.js index 3ad890e..7a6d2f2 100644 --- a/src/Route.js +++ b/src/Route.js @@ -1,5 +1,5 @@ /** - * @secjs/esm + * @secjs/utils * * (c) João Lenon * diff --git a/src/String.js b/src/String.js index be142a7..e46d645 100644 --- a/src/String.js +++ b/src/String.js @@ -1,5 +1,5 @@ /** - * @secjs/esm + * @secjs/utils * * (c) João Lenon * diff --git a/src/Uuid.js b/src/Uuid.js index f9ed606..9d293f3 100644 --- a/src/Uuid.js +++ b/src/Uuid.js @@ -1,5 +1,5 @@ /** - * @secjs/esm + * @secjs/utils * * (c) João Lenon * diff --git a/tests/Stubs/config/app.js b/tests/Stubs/config/app.js index 8e4f08c..3faeca9 100644 --- a/tests/Stubs/config/app.js +++ b/tests/Stubs/config/app.js @@ -1,5 +1,5 @@ /** - * @secjs/esm + * @secjs/utils * * (c) João Lenon * diff --git a/tests/Stubs/config/database.js b/tests/Stubs/config/database.js index c78931b..7d7a26a 100644 --- a/tests/Stubs/config/database.js +++ b/tests/Stubs/config/database.js @@ -1,5 +1,5 @@ /** - * @secjs/esm + * @secjs/utils * * (c) João Lenon * diff --git a/tests/Stubs/config/notNormalized.js b/tests/Stubs/config/notNormalized.js index 8a27200..f15a496 100644 --- a/tests/Stubs/config/notNormalized.js +++ b/tests/Stubs/config/notNormalized.js @@ -1,5 +1,5 @@ /** - * @secjs/esm + * @secjs/utils * * (c) João Lenon * diff --git a/tests/Stubs/config/recursiveOne.js b/tests/Stubs/config/recursiveOne.js index 9d42c3b..93b1a32 100644 --- a/tests/Stubs/config/recursiveOne.js +++ b/tests/Stubs/config/recursiveOne.js @@ -1,5 +1,5 @@ /** - * @secjs/esm + * @secjs/utils * * (c) João Lenon * diff --git a/tests/Stubs/config/recursiveTwo.js b/tests/Stubs/config/recursiveTwo.js index db13f67..6b2b427 100644 --- a/tests/Stubs/config/recursiveTwo.js +++ b/tests/Stubs/config/recursiveTwo.js @@ -1,5 +1,5 @@ /** - * @secjs/esm + * @secjs/utils * * (c) João Lenon * diff --git a/tests/Unit/CleanTest.js b/tests/Unit/CleanTest.js index 3b80fbd..23f1f64 100644 --- a/tests/Unit/CleanTest.js +++ b/tests/Unit/CleanTest.js @@ -1,5 +1,5 @@ /** - * @secjs/esm + * @secjs/utils * * (c) João Lenon * diff --git a/tests/Unit/ConfigTest.js b/tests/Unit/ConfigTest.js index 6564de4..4563b7f 100644 --- a/tests/Unit/ConfigTest.js +++ b/tests/Unit/ConfigTest.js @@ -1,5 +1,5 @@ /** - * @secjs/esm + * @secjs/utils * * (c) João Lenon * diff --git a/tests/Unit/DebugTest.js b/tests/Unit/DebugTest.js index 48aad11..3227960 100644 --- a/tests/Unit/DebugTest.js +++ b/tests/Unit/DebugTest.js @@ -1,5 +1,5 @@ /** - * @secjs/esm + * @secjs/utils * * (c) João Lenon * diff --git a/tests/Unit/ExceptionTest.js b/tests/Unit/ExceptionTest.js index 088c098..c30883b 100644 --- a/tests/Unit/ExceptionTest.js +++ b/tests/Unit/ExceptionTest.js @@ -1,5 +1,5 @@ /** - * @secjs/esm + * @secjs/utils * * (c) João Lenon * diff --git a/tests/Unit/ExecTest.js b/tests/Unit/ExecTest.js index 3dd8582..1039dc7 100644 --- a/tests/Unit/ExecTest.js +++ b/tests/Unit/ExecTest.js @@ -1,5 +1,5 @@ /** - * @secjs/esm + * @secjs/utils * * (c) João Lenon * diff --git a/tests/Unit/FileTest.js b/tests/Unit/FileTest.js index 58be71f..fdd21ce 100644 --- a/tests/Unit/FileTest.js +++ b/tests/Unit/FileTest.js @@ -1,5 +1,5 @@ /** - * @secjs/esm + * @secjs/utils * * (c) João Lenon * diff --git a/tests/Unit/FolderTest.js b/tests/Unit/FolderTest.js index 817d542..8baebf0 100644 --- a/tests/Unit/FolderTest.js +++ b/tests/Unit/FolderTest.js @@ -1,5 +1,5 @@ /** - * @secjs/esm + * @secjs/utils * * (c) João Lenon * diff --git a/tests/Unit/IsTest.js b/tests/Unit/IsTest.js index 71df84d..c64b7be 100644 --- a/tests/Unit/IsTest.js +++ b/tests/Unit/IsTest.js @@ -1,5 +1,5 @@ /** - * @secjs/esm + * @secjs/utils * * (c) João Lenon * diff --git a/tests/Unit/JsonTest.js b/tests/Unit/JsonTest.js index 4a99899..23f3963 100644 --- a/tests/Unit/JsonTest.js +++ b/tests/Unit/JsonTest.js @@ -1,5 +1,5 @@ /** - * @secjs/esm + * @secjs/utils * * (c) João Lenon * diff --git a/tests/Unit/NumberTest.js b/tests/Unit/NumberTest.js index 1233a72..adc2f89 100644 --- a/tests/Unit/NumberTest.js +++ b/tests/Unit/NumberTest.js @@ -1,5 +1,5 @@ /** - * @secjs/esm + * @secjs/utils * * (c) João Lenon * diff --git a/tests/Unit/ParserTest.js b/tests/Unit/ParserTest.js index 74389bb..db11490 100644 --- a/tests/Unit/ParserTest.js +++ b/tests/Unit/ParserTest.js @@ -1,5 +1,5 @@ /** - * @secjs/esm + * @secjs/utils * * (c) João Lenon * diff --git a/tests/Unit/PathTest.js b/tests/Unit/PathTest.js index f4398b7..7337f0b 100644 --- a/tests/Unit/PathTest.js +++ b/tests/Unit/PathTest.js @@ -1,5 +1,5 @@ /** - * @secjs/esm + * @secjs/utils * * (c) João Lenon * diff --git a/tests/Unit/RouteTest.js b/tests/Unit/RouteTest.js index de41390..2f58d1b 100644 --- a/tests/Unit/RouteTest.js +++ b/tests/Unit/RouteTest.js @@ -1,5 +1,5 @@ /** - * @secjs/esm + * @secjs/utils * * (c) João Lenon * diff --git a/tests/Unit/StringTest.js b/tests/Unit/StringTest.js index 52f14e4..61392d2 100644 --- a/tests/Unit/StringTest.js +++ b/tests/Unit/StringTest.js @@ -1,5 +1,5 @@ /** - * @secjs/esm + * @secjs/utils * * (c) João Lenon * diff --git a/tests/Unit/UuidTest.js b/tests/Unit/UuidTest.js index af3dbb4..a473301 100644 --- a/tests/Unit/UuidTest.js +++ b/tests/Unit/UuidTest.js @@ -1,5 +1,5 @@ /** - * @secjs/esm + * @secjs/utils * * (c) João Lenon *