{"id":18562897,"url":"https://github.com/fullstackplayer/fsp.niceerror","last_synced_at":"2026-04-30T13:33:25.008Z","repository":{"id":57242492,"uuid":"346619510","full_name":"FullStackPlayer/fsp.NiceError","owner":"FullStackPlayer","description":"An extension for TS/JS Error Object, brings you better development experience.","archived":false,"fork":false,"pushed_at":"2022-09-26T10:04:15.000Z","size":174,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-20T14:43:37.768Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/FullStackPlayer.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-03-11T07:46:06.000Z","updated_at":"2021-12-23T05:49:38.000Z","dependencies_parsed_at":"2022-09-09T04:01:26.406Z","dependency_job_id":null,"html_url":"https://github.com/FullStackPlayer/fsp.NiceError","commit_stats":null,"previous_names":["fullstackplayer/ts-niceerror"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FullStackPlayer%2Ffsp.NiceError","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FullStackPlayer%2Ffsp.NiceError/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FullStackPlayer%2Ffsp.NiceError/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FullStackPlayer%2Ffsp.NiceError/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/FullStackPlayer","download_url":"https://codeload.github.com/FullStackPlayer/fsp.NiceError/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254394726,"owners_count":22063984,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-06T22:11:21.659Z","updated_at":"2025-12-11T21:13:37.458Z","avatar_url":"https://github.com/FullStackPlayer.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# fsp.NiceError\nAn extension for TS/JS Error Object, brings you better development experience.\n\n# Features:\n- traceable, intuitional error chain\n- support extra infomation\n- zero dependency\n- support both nodejs and deno runtime\n\n# Import to your project\n\n### For Node.js\nInstall it first:\n~~~bash\n # pay attention to the package name 'fsp-nice-error'\nnpm install fsp-nice-error\n # or\nyarn add fsp-nice-error\n~~~\n\nThen import it:\n~~~js\n// CommonJS\nconst { NiceError } = require('fsp-nice-error')\n// ES Module or TypeScript, need bundlers(rollup/webpack/parcel...) support for current nodejs version\nimport { NiceError } from 'fsp-nice-error'\n~~~\n\n### For Deno\n\n#### Option 1\nJust copy `src/NiceError.ts` file to your project, and then import it:\n~~~ts\nimport { NiceError } from \"path/to/NiceError.ts\"\n~~~\n\n#### Option 2\nDirectly import it from remote sources:\n~~~ts\n// from denopkg\nimport { NiceError } from \"https://denopkg.com/FullStackPlayer/fsp.NiceError@master/mod.ts\"\n// from deno.land\nimport { NiceError } from \"https://deno.land/x/fsp_nice_error/mod.ts\"\n~~~\n\n# Usage\n\n#### For better experience\nSet static property `execPath` for NiceError will shorten the trace stack info.\n~~~js\n// nodejs\nNiceError.execPath = process.cwd()\n// deno\nNiceError.execPath = Deno.cwd()\n~~~\n\n#### Handling inner error\n\n~~~js\n// a normal js Error\nconst err = new Error('This is a normal error')\n\n// a NiceError which takes err as it's inner error\nconst ne1 = new NiceError('A normal error was caught!',{\n    name: 'NiceError',\n    cause: err,\n    info: {\n        foo: 'foo'\n    }\n})\n\n// another NiceError which takes ne1 as it's inner error\nconst ne2 = new NiceError('An inner NiceError was caught!',{\n    name: 'AppError',\n    cause: ne1,\n    info: {\n        bar: 'bar'\n    }\n})\n\nconsole.log(ne2.message)\n/**\noutput:\n------------------------------\nAn inner NiceError was caught!\n------------------------------\n*/\n\nconsole.log(ne2.fullMessage())\n/**\noutput:\n------------------------------\n[AppError]: An inner NiceError was caught! \u003c= [NiceError]: A normal error was caught! \u003c= [Error]: This is a normal error\n------------------------------\n*/\n\nconsole.log(ne2.fullStack())\n/**\noutput:\n------------------------------\n[AppError]: An inner NiceError was caught! \u003c= [NiceError]: A normal error was caught! \u003c= [Error]: This is a normal error\n    at Object.\u003canonymous\u003e (./sample/nodeEnv.js:16:11)\n    at Module._compile (internal/modules/cjs/loader.js:1063:30)\n    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)\n    at Module.load (internal/modules/cjs/loader.js:928:32)\n    at Function.Module._load (internal/modules/cjs/loader.js:769:14)\n    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)\n    at internal/main/run_main_module.js:17:47\nCaused by [NiceError]: A normal error was caught! \u003c= [Error]: This is a normal error\n    at Object.\u003canonymous\u003e (./sample/nodeEnv.js:7:11)\n    at Module._compile (internal/modules/cjs/loader.js:1063:30)\n    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)\n    at Module.load (internal/modules/cjs/loader.js:928:32)\n    at Function.Module._load (internal/modules/cjs/loader.js:769:14)\n    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)\n    at internal/main/run_main_module.js:17:47\nCaused by [Error]: This is a normal error\n    at Object.\u003canonymous\u003e (./sample/nodeEnv.js:4:11)\n    at Module._compile (internal/modules/cjs/loader.js:1063:30)\n    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)\n    at Module.load (internal/modules/cjs/loader.js:928:32)\n    at Function.Module._load (internal/modules/cjs/loader.js:769:14)\n    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)\n    at internal/main/run_main_module.js:17:47\n*/\n\nconsole.log(ne2.fullInfo())\n/**\noutput:\n------------------------------\n{\n    foo: 'foo',\n    bar: 'bar'\n}\n------------------------------\n*/\n~~~\n\n#### Handling unexpected thown object as inner error\n\n~~~js\nconst err = { foo: 'bar'}\ntry {\n    // just throw an object\n    throw err\n}\ncatch(err) {\n    // a NiceError which takes the thrown object as inner err\n    const ne1 = new NiceError('An object was thrown',{\n        name: 'NiceError',\n        cause: err\n    })\n\n    console.log(ne1.fullMessage())\n    /**\n    output:\n    ------------------------------\n    [NiceError]: An object was thrown \u003c= [Throw]: type = object, content = {\"foo\":\"bar\"}\n    ------------------------------\n    */\n\n    console.log(ne1.fullStack())\n    /**\n    output:\n    ------------------------------\n    [NiceError]: An object was thrown \u003c= [Throw]: type = object, content = {\"foo\":\"bar\"}\n        at Object.\u003canonymous\u003e (./sample/nodeEnv.js:39:15)\n        at Module._compile (internal/modules/cjs/loader.js:1063:30)\n        at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)\n        at Module.load (internal/modules/cjs/loader.js:928:32)\n        at Function.Module._load (internal/modules/cjs/loader.js:769:14)\n        at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)\n        at internal/main/run_main_module.js:17:47\n    Caused by [Throw]: type = object, content = {\"foo\":\"bar\"}\n        at Object.\u003canonymous\u003e (./sample/nodeEnv.js:46:21)\n        at Module._compile (internal/modules/cjs/loader.js:1063:30)\n        at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)\n        at Module.load (internal/modules/cjs/loader.js:928:32)\n        at Function.Module._load (internal/modules/cjs/loader.js:769:14)\n        at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)\n        at internal/main/run_main_module.js:17:47\n    ------------------------------\n    */\n}\n~~~\n\n#### NiceError with chain property\n\n~~~js\ntry {\n    throw new NiceError('NiceError With Chain', {\n        chain: ['root','folder']\n    })\n}\ncatch(ex) {\n    console.log(ex.fullMessage())\n    /**\n    output:\n    ------------------------------\n    [NiceError@root/folder]: NiceError With Chain\n    ------------------------------\n    */\n}\n~~~\n\n# **API**\n\n### Class NiceError\n\n- Static Property\n    - execPath - String - script base path for replacing it from stack info\n- Property\n    - name - String - error name\n    - message - String - error message\n    - chain - String[] - error chain array\n    - info - Object - context infomation about the error\n    - stack - String - stack trace of the error\n- Method\n    - fullMessage() - String - get all the messages of the error chain path \n    - fullStack() - String - get all the stack infomations of the error chain path\n    - fullInfo() - Object - merge all the info objects in this error chain into one big info object\n\n\n## Enjoy it :-)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffullstackplayer%2Ffsp.niceerror","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffullstackplayer%2Ffsp.niceerror","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffullstackplayer%2Ffsp.niceerror/lists"}