# Logging function
# Usage: log "message" [--nl]
log() {
    local message="$1"
    local mode="$2"
    local nl=""

    # If the second argument is --nl, add the newlines
    if [[ "$mode" == "--nl" ]]; then
        nl="\n"
    fi

    echo -e "${nl}\e[33m[INFO] ${message} \e[0m${nl}"
}

# Logging function
log_error() {
    echo -e "\n\e[31m[ERROR] $1 \e[0m \n"
}

# Error handling function
handle_error() {
    log_error "An error occurred on line $1."
    # workaround: exit 1 will cause the shell sourcing a script to exit 
    if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
        exit 1
    fi
    return 1
}

# Trap errors
trap 'handle_error $LINENO' ERR
