Coder Social home page Coder Social logo

trapper's Introduction

DevelopersToolbox logo
Github Build Status Release Commits since release

Overview

At Wolf Software we write a lot of bash scripts for many purposes and the one thing that we found lacking was a simple to use debugging tool.

Trapper is something that weas developed originally for internal use to debug scripts we release with the aim being a simple plugin that required minimal changes to the original script.

Trapper is capable of capturing a large array of runtime errors and attempts to point to where the error happened.

Usage

Simply source trapper at the top of your script and then execute it as normal.

Trapper works by setting a trap for any errors and attempts to display where the errors happened.

Truncated snippet

set -Eeuo pipefail

function trap_with_arg()
{
    func="$1";
    shift

    for sig ; do
        # shellcheck disable=SC2064
        trap "$func $sig" "$sig"
    done
}

trap_with_arg 'failure ${?}' ERR EXIT

It is capable of detecting errors in a many different scenarios.

Scenario Requirements Results
Single script Include trapper.sh Reports filename, line number and code snippet.
Excuting scripts Include trapper.sh (in all scripts) Reports filename, line number and code snippet for full stack trace (calling scripts).
Including scripts Include trapper.sh (only in parent script) Reports filename, line number and code snipper of the failing included script.

Examples

Testing for unset (unbound) variables

Single script attempt to use an unbound variable.

Source

Unbounded

Testing execute stack (scripts calling scripts)

Parent script executing child script with error in the final child.

Source

Execute Stack

Testing source stack (scripts including scripts)

Parent script including (sourcing) child scripts with an error in the final child.

Source

Execute Stack

trapper's People

Contributors

tgwolf avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.