{"id":28252684,"url":"https://github.com/iptoux/bash_error_lib","last_synced_at":"2025-07-19T22:04:58.788Z","repository":{"id":64917657,"uuid":"577449752","full_name":"iptoux/bash_error_lib","owner":"iptoux","description":"An standalone bash \"library\" that catches mostly all errors of an bash script.","archived":false,"fork":false,"pushed_at":"2022-12-29T00:54:23.000Z","size":5534,"stargazers_count":4,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-15T20:36:57.836Z","etag":null,"topics":["bash","cli","error","error-handler","library","linux","linux-shell"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"cc0-1.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/iptoux.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2022-12-12T19:07:27.000Z","updated_at":"2025-02-03T16:19:06.000Z","dependencies_parsed_at":"2023-01-31T07:45:29.789Z","dependency_job_id":null,"html_url":"https://github.com/iptoux/bash_error_lib","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/iptoux/bash_error_lib","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iptoux%2Fbash_error_lib","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iptoux%2Fbash_error_lib/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iptoux%2Fbash_error_lib/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iptoux%2Fbash_error_lib/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/iptoux","download_url":"https://codeload.github.com/iptoux/bash_error_lib/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iptoux%2Fbash_error_lib/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266026264,"owners_count":23866032,"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":["bash","cli","error","error-handler","library","linux","linux-shell"],"created_at":"2025-05-19T16:16:21.869Z","updated_at":"2025-07-19T22:04:58.386Z","avatar_url":"https://github.com/iptoux.png","language":"Shell","readme":"# bash_error_lib\n\n\u003cp align=\"center\" width=\"100%\"\u003e\n    \u003cimg src=\"https://img.shields.io/github/package-json/v/iptoux/bash_error_lib?style=for-the-badge\" title=\"GitHub package.json version\"\u003e\n    \u003cimg src=\"https://img.shields.io/github/directory-file-count/iptoux/bash_error_lib/lib?style=for-the-badge\" title=\"GitHub repo file count (file extension)\"\u003e\n    \u003cimg src=\"https://img.shields.io/github/languages/code-size/iptoux/bash_error_lib?style=for-the-badge\" title=\"GitHub code size in bytes\"\u003e\n    \u003cimg src=\"https://img.shields.io/github/issues/iptoux/bash_error_lib?style=for-the-badge\" title=\"GitHub issues\"\u003e\n    \u003cimg src=\"https://img.shields.io/github/license/iptoux/bash_error_lib?style=for-the-badge\" title=\"GitHub\"\u003e\n    \u003cimg src=\"https://img.shields.io/github/package-json/keywords/iptoux/bash_error_lib?style=flat-square\" title=\"GitHub package.json dynamic\"\u003e \n\u003c/p\u003e\n\nThis is an bash error \"library\", an error handler for any kind of bash script. The library catches mostly all errors by an trap and displays/logs them. The library includes:\n\n- error logging\n- debug logging\n- display stack\n- colors \u0026 (themes)\n- own manual manages\n- STANDALONE SINGLEFILE!\n\n## Index\n\n\n- [Why](https://github.com/iptoux/bash_error_lib#why)\n- [How it works](https://github.com/iptoux/bash_error_lib#how-it-works)\n- [Control](https://github.com/iptoux/bash_error_lib#control)\n- [Screenshots/Output](https://github.com/iptoux/bash_error_lib#screenshotsoutput)\n- [HowTo/Usage/Install](https://github.com/iptoux/bash_error_lib#howto)\n- [Example](https://github.com/iptoux/bash_error_lib#example)\n- [Todo](https://github.com/iptoux/bash_error_lib#todo)\n\n\n\n## Why?\n---\nWhile i build an install script, that installs my own, linux i3wm desktop, i nothiced that:\n\n- The errors not shown nicely\n- The handling of the errors is....\n- I like unixporn, not only on desktop, also on cli output!\n\nDuring the defualt search on the internet i dont find any good solution.\nAn Package, an all in one suite, that is easy to include and use.\n\n## How it works\n---\nAn trap, set in the begin of any kind of bash script, calls the error handler function. The function reads the vars given by trap. Than it loads the error from the redirected stderr and merges them into and error container. After some checks of user variables(debug/log/stack), the output message will be build and printed.\n\n## Control\n\n- [ ] Option to exit on error\n- [x] Option to enable/disable logging (file)\n- [x] Option to display errorstack\n- [x] Option to display source code snipped (from called error)\n- [x] Option to enable colors on output\n- [x] Option to enable debug (also via cmd option)\n- [x] Option to set manual errors on any line.\n\n## Screenshots/Output\n---\n\n**CLI-TRAP**\n```console\niptoux@2040:~/gits/bash_error_lib$ ./basherr.sh \n\n------------------------------------------------\n\u003e\u003e ERROR (1) - General/External script error.\n\n\u003e\u003e MSG: No such file or directory\n\u003e\u003e CALL/CMD/ARG: lol\n\n\u003e\u003e CAUSE BY: cat IN: ./basherr.sh ON LINE: 50\n\u003e\u003e FULLSTACK:\n    huhu @ ./basherr.sh:50\n    main @ ./basherr.sh:54\n\n\u003e\u003e SNIPPED:\n\n\u003e\u003e -\u003e 08 lines of source from  \u003c-\n\u003e\u003e {\nL:46      #somecommand        # \u003c-\nL:47      \nL:48      huhu() {\nL:49      \nL:50   \u003e\u003e\u003e    cat lol\nL:51      \nL:52      }\nL:53      \nL:54      huhu\n\u003e\u003e }\n\n\u003e\u003e There are 6 log files in folder, cleaning....\n\u003e\u003e Execution time: 0.322949 seconds\niptoux@2040:~/gits/bash_error_lib$ \n```\n\n**CLI-MANUAL**\n```console\niptoux@2040:~/gits/bash_error_lib$ ./basherr.sh \n\n------------------------------------------------\n\u003e\u003e ERROR (1) - (M): General/External script error.\n\n\u003e\u003e MSG: this is an random error\n\u003e\u003e CALL/CMD/ARG: N/A (see message)\n\u003e\u003e CAUSE BY: huhu IN: ./basherr.sh ON LINE: 50\n\n\u003e\u003e SNIPPED:\n\n\u003e\u003e -\u003e 06 lines of source from ./basherr.sh \u003c-\n\u003e\u003e {\nL:47      \nL:48      huhu() {\nL:49      \nL:50   \u003e\u003e\u003e_error \"this is an random error\"\nL:51      \nL:52      }\nL:53      \n\u003e\u003e }\n\n\u003e\u003e There are 6 debug log files in folder, cleaning....\n\u003e\u003e  Execution time: 0.17364144325256348 seconds\n\niptoux@2040:~/gits/bash_error_lib$\n```\n\n**DEBUG-LOG FILE**\n```\niptoux@2040:~/gits/bash_error_lib$ ./basherr.sh\niptoux@2040:~/gits/bash_error_lib$ cat 12.15.22_1835637.log \n- [T]: 22:38:47 [F]: basherr.sh [M]:  [L]: 26 [C]: trap 'bs_error \"$?\" \"${FUNCNAME[0]}\"' ERR\n- [T]: 22:38:47 [F]: basherr.sh [M]:  [L]: 27 [C]: trap 'bs_error \"$?\" \"${FUNCNAME[0]}\"' EXIT\n- [T]: 22:38:47 [F]: basherr.sh [M]:  [L]: 28 [C]: trap bs_clean EXIT\n- [T]: 22:38:47 [F]: basherr.sh [M]:  [L]: 42 [C]: bs_debug false\n- [T]: 22:38:47 [F]: bash_error_lib [M]: bs_debug [L]: 176 [C]: switch=false\n- [T]: 22:38:47 [F]: bash_error_lib [M]: bs_debug [L]: 178 [C]: '[' false == auto ']'\n- [T]: 22:38:47 [F]: bash_error_lib [M]: bs_debug [L]: 178 [C]: '[' false == true ']'\n- [T]: 22:38:47 [F]: bash_error_lib [M]: bs_debug [L]: 187 [C]: '[' false == false ']'\n- [T]: 22:38:47 [F]: bash_error_lib [M]: bs_debug [L]: 188 [C]: set +o xtrace\niptoux@2040:~/gits/bash_error_lib$ \n```\n\n**ERROR-LOG FILE**\n```\n\u003e\u003e Date/Time: 23.12.2022 - 23:44:38\n------------------------------------------------\n\u003e\u003e ERROR (1) - General/External script error.\n\n\u003e\u003e MSG: No such file or directory\n\u003e\u003e CALL/CMD/ARG: lol\n\n\u003e\u003e CAUSE BY: cat IN: ./basherr.sh ON LINE: 50\n\u003e\u003e FULLSTACK:\n    huhu @ ./basherr.sh:50\n    main @ ./basherr.sh:54\n\n\u003e\u003e SNIPPED:\n\n\u003e\u003e -\u003e 08 lines of source from  \u003c-\n\u003e\u003e {\nL:46      #somecommand        # \u003c-\nL:47      \nL:48      huhu() {\nL:49      \nL:50   \u003e\u003e\u003e    cat lol\nL:51      \nL:52      }\nL:53      \nL:54      huhu\n\u003e\u003e }\n```\n\n---\n\n**IMAGES**\n\n- default error with color\n\n![default error with color](../assets/v1.2.4/color_default_error.png)\n\n- syntax error without color (also with possible)\n\n![syntax error without color](../assets/v1.2.4/nocolor_syntax_error.png)\n\n- manual error with color\n\n![manual error with color](../assets/v1.2.4/color_manual.png)\n\n- external error without color (also with possible)\n\n![external error without color](../assets/v1.2.4/nocolor_external.png)\n\n\n\n## HowTo\n---\nIn the next parts follow an explaination how to use the \"library\".\n\n**Cloning:**\n\nDownload repositorys latest zip or clone to your local storage.\nCopy file into your script directory (can an subdirectory too)\n\n**Including in an scipt:**\n\nSource file in your script\n\n```\n. 'path/to/library_file'\n```\n\nSet Traps\n\n```\n# setting up Traps\ntrap 'bs_error_trap \"$?\" \"${BASH_SOURCE[0]}\" \"${LINENO}\" \"${FUNCNAME}\"' ERR\ntrap 'bs_error_trap \"$?\" \"${BASH_SOURCE[0]}\" \"${LINENO}\" \"${FUNCNAME}\"' EXIT\n\n```\n\n**Done**\n\nYes! thats all, now the library is ready an loaded in your script when you run it next time.\n\n## Example?\n\nThe `basherr.sh` in the repo is an example, that shows how to include in your script and calls errors. All files are \"well\" documented.\n\n## ToDo\n\n- [ ] More documentation","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiptoux%2Fbash_error_lib","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fiptoux%2Fbash_error_lib","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiptoux%2Fbash_error_lib/lists"}