def parse_qsub_error(output):
    """Parse and return error output of a failed qsub command.

    :param output: stderr of qsub command
    :type output: str
    :returns: error message
    :rtype: str
    """
    # look for error first
    for line in output.split("\n"):
        if line.startswith("qsub:"):
            error = line.split(":")[1]
            return error.strip()
    # if no error line, take first line
    for line in output.split("\n"):
        return line.strip()
    # if neither, present a base error message
    base_err = "PBS run error"
    return base_err