Skip to content

Commit

Permalink
Merge pull request #536 from JrGoodle/error-refactor
Browse files Browse the repository at this point in the history
Error refactor
  • Loading branch information
JrGoodle committed May 27, 2020
2 parents ee65136 + 93e5f15 commit 62c64bc
Show file tree
Hide file tree
Showing 50 changed files with 1,187 additions and 953 deletions.
24 changes: 12 additions & 12 deletions .github/workflows/cancel.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
name: Cancel
# name: Cancel

on: [push]
# on: [push]

jobs:
cancel:
name: 'Cancel Previous Runs'
runs-on: ubuntu-latest
timeout-minutes: 3
steps:
- uses: styfle/cancel-workflow-action@0.3.1
with:
workflow_id: 1302111, 1302112, 1302113, 1302114, 1302115, 1302116, 1302117, 1302118, 1302119, 1302120, 1302121, 1302122, 1302123, 1302124, 1302125, 1302126, 1302127, 1302128, 1302129, 1302130, 1302131, 1302132, 1302133, 1302134, 1302135, 1302136, 1302137, 1304392
access_token: ${{ github.token }}
# jobs:
# cancel:
# name: 'Cancel Previous Runs'
# runs-on: ubuntu-latest
# timeout-minutes: 3
# steps:
# - uses: styfle/cancel-workflow-action@0.3.1
# with:
# workflow_id: 1302111, 1302112, 1302113, 1302114, 1302115, 1302116, 1302117, 1302118, 1302119, 1302120, 1302121, 1302122, 1302123, 1302124, 1302125, 1302126, 1302127, 1302128, 1302129, 1302130, 1302131, 1302132, 1302133, 1302134, 1302135, 1302136, 1302137, 1304392
# access_token: ${{ github.token }}
31 changes: 5 additions & 26 deletions src/clowder/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,14 @@
"""

import logging
import os
import traceback
from pathlib import Path
from typing import Optional

from clowder.error import ClowderExit
from clowder.error import ClowderError, ClowderErrorType
from clowder.logging import LOG_DEBUG
from clowder.util.formatting import error_ambiguous_clowder_yaml
from clowder.git.util import existing_git_repository

# Set up logging #

PRINT_DEBUG_OUTPUT = "CLOWDER_DEBUG" in os.environ
logging.basicConfig()
logging.raiseExceptions = True
logger = logging.getLogger("CLOWDER")
if PRINT_DEBUG_OUTPUT:
logger.setLevel(logging.DEBUG)
else:
logger.setLevel(logging.ERROR)


def LOG_DEBUG(message: str, exception: Optional[Exception] = None): # noqa
if PRINT_DEBUG_OUTPUT:
logger.log(logging.DEBUG, f" {message}")
if exception is not None:
# TODO: Format the output for clowder debug
traceback.print_exc()


# Set up global paths #

Expand Down Expand Up @@ -76,11 +55,11 @@ def existing_clowder_repo(directory: Path) -> bool:
if clowder_yml.is_symlink() and clowder_yaml.is_symlink():
print(error_ambiguous_clowder_yaml())
try:
raise ClowderExit(1)
except ClowderExit as err:
raise ClowderError(ClowderErrorType.AMBIGUOUS_CLOWDER_YAML, error_ambiguous_clowder_yaml())
except ClowderError as err:
LOG_DEBUG('Ambigiuous clowder file', err)
print()
exit(err.code)
exit(err.error_type.value)
if clowder_yml.is_symlink():
CLOWDER_YAML = clowder_yml
elif clowder_yaml.is_symlink():
Expand Down
5 changes: 5 additions & 0 deletions src/clowder/cli/branch.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@


def add_branch_parser(subparsers: argparse._SubParsersAction) -> None: # noqa
"""Add clowder branch parser
:param argparse._SubParsersAction subparsers: Subparsers action to add parser to
"""

arguments = [
(['projects'], dict(metavar='PROJECT', default='default', nargs='*',
Expand All @@ -47,6 +51,7 @@ def add_branch_parser(subparsers: argparse._SubParsersAction) -> None: # noqa
@print_clowder_repo_status
def branch(args) -> None:
"""Clowder branch command private implementation"""

if args.remote:
local = False
remote = True
Expand Down
4 changes: 4 additions & 0 deletions src/clowder/cli/checkout.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@


def add_checkout_parser(subparsers: argparse._SubParsersAction) -> None: # noqa
"""Add clowder checkout parser
:param argparse._SubParsersAction subparsers: Subparsers action to add parser to
"""

arguments = [
(['branch'], dict(nargs=1, action='store', help='branch to checkout', metavar='BRANCH')),
Expand Down
4 changes: 4 additions & 0 deletions src/clowder/cli/clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@


def add_clean_parser(subparsers: argparse._SubParsersAction) -> None: # noqa
"""Add clowder clean parser
:param argparse._SubParsersAction subparsers: Subparsers action to add parser to
"""

arguments = [
(['projects'], dict(metavar='PROJECT', default='default', nargs='*',
Expand Down
23 changes: 18 additions & 5 deletions src/clowder/cli/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@


def add_config_parser(subparsers: argparse._SubParsersAction) -> None: # noqa
"""Clowder config command controller"""
"""Add clowder config parser
:param argparse._SubParsersAction subparsers: Subparsers action to add parser to
"""

parser = subparsers.add_parser('config', help='Manage clowder config (EXPERIMENTAL)')
config_subparsers = parser.add_subparsers()
Expand All @@ -30,7 +33,10 @@ def add_config_parser(subparsers: argparse._SubParsersAction) -> None: # noqa


def add_config_clear_parser(subparsers: argparse._SubParsersAction) -> None: # noqa
"""Clowder config clear command controller"""
"""Add clowder config clear parser
:param argparse._SubParsersAction subparsers: Subparsers action to add parser to
"""

# clowder config clear
config_clear_parser = subparsers.add_parser('clear', help='Clear clowder config options')
Expand All @@ -56,7 +62,10 @@ def add_config_clear_parser(subparsers: argparse._SubParsersAction) -> None: # n


def add_config_get_parser(subparsers: argparse._SubParsersAction) -> None: # noqa
"""Clowder config get command controller"""
"""Add clowder config get parser
:param argparse._SubParsersAction subparsers: Subparsers action to add parser to
"""

# clowder config get
config_get_parser = subparsers.add_parser('get', help='Get clowder config options')
Expand All @@ -82,7 +91,10 @@ def add_config_get_parser(subparsers: argparse._SubParsersAction) -> None: # noq


def add_config_set_parser(subparsers: argparse._SubParsersAction) -> None: # noqa
"""Clowder config set command controller"""
"""Add clowder config set parser
:param argparse._SubParsersAction subparsers: Subparsers action to add parser to
"""

# clowder config set
parser = subparsers.add_parser('set', help='Set clowder config options')
Expand Down Expand Up @@ -185,7 +197,8 @@ def config_clear_rebase(args) -> None: # noqa
def config_get_all(args) -> None: # noqa
"""Clowder config get all command entry point"""

print(' - Get all config values\n')
print(' - Get all config values')
print()
config = Config(CLOWDER_CONTROLLER.name, CLOWDER_CONTROLLER.project_choices)
config.current_clowder_config.print_configuration()

Expand Down
4 changes: 4 additions & 0 deletions src/clowder/cli/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@


def add_diff_parser(subparsers: argparse._SubParsersAction) -> None: # noqa
"""Add clowder diff parser
:param argparse._SubParsersAction subparsers: Subparsers action to add parser to
"""

arguments = [
(['projects'], dict(metavar='PROJECT', default='default', nargs='*',
Expand Down
4 changes: 4 additions & 0 deletions src/clowder/cli/forall.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@


def add_forall_parser(subparsers: argparse._SubParsersAction) -> None: # noqa
"""Add clowder forall parser
:param argparse._SubParsersAction subparsers: Subparsers action to add parser to
"""

arguments = [
(['projects'], dict(metavar='PROJECT', default='default', nargs='*',
Expand Down
4 changes: 4 additions & 0 deletions src/clowder/cli/herd.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@


def add_herd_parser(subparsers: argparse._SubParsersAction) -> None: # noqa
"""Add clowder herd parser
:param argparse._SubParsersAction subparsers: Subparsers action to add parser to
"""

arguments = [
(['projects'], dict(metavar='PROJECT', default='default', nargs='*',
Expand Down
10 changes: 5 additions & 5 deletions src/clowder/cli/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@

import argparse

from termcolor import colored, cprint
from termcolor import colored

import clowder.clowder_repo as clowder_repo
import clowder.util.formatting as fmt
from clowder import CURRENT_DIR, existing_clowder_repo
from clowder.error import ClowderExit
from clowder.error import ClowderError, ClowderErrorType
from clowder.util.connectivity import network_connection_required

from .util import add_parser_arguments
Expand All @@ -33,13 +34,12 @@ def add_init_parser(subparsers: argparse._SubParsersAction) -> None: # noqa
def init(args) -> None:
"""Clowder init command private implementation
:raise ClowderExit:
:raise ClowderError:
"""

clowder_repo_dir = CURRENT_DIR / '.clowder'
if existing_clowder_repo(clowder_repo_dir):
cprint('Clowder already initialized in this directory\n', 'red')
raise ClowderExit(1)
raise ClowderError(ClowderErrorType.CLOWDER_ALREADY_INITIALIZED, fmt.error_clowder_already_initialized())

url_output = colored(args.url, 'green')
print(f"Create clowder repo from {url_output}\n")
Expand Down
4 changes: 4 additions & 0 deletions src/clowder/cli/link.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@


def add_link_parser(subparsers: argparse._SubParsersAction) -> None: # noqa
"""Add clowder link parser
:param argparse._SubParsersAction subparsers: Subparsers action to add parser to
"""

versions = get_saved_version_names()

Expand Down
23 changes: 12 additions & 11 deletions src/clowder/cli/prune.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@
import argparse
from typing import List, Tuple

from termcolor import cprint

import clowder.util.formatting as fmt
from clowder.clowder_controller import CLOWDER_CONTROLLER
from clowder.config import Config
from clowder.error import ClowderError
from clowder.error import ClowderError, ClowderErrorType
from clowder.logging import LOG_DEBUG
from clowder.model import Project
from clowder.model.util import (
existing_branch_projects,
Expand All @@ -31,6 +30,10 @@


def add_prune_parser(subparsers: argparse._SubParsersAction): # noqa
"""Add clowder prune parser
:param argparse._SubParsersAction subparsers: Subparsers action to add parser to
"""

arguments = [
(['branch'], dict(help='name of branch to remove', metavar='BRANCH')),
Expand Down Expand Up @@ -120,8 +123,9 @@ def _prune_projects(projects: Tuple[Project, ...], branch: str, force: bool = Fa

try:
_validate_branches(local, remote, local_branch_exists, remote_branch_exists)
except ClowderError:
pass
except ClowderError as err:
LOG_DEBUG('Invalid projects branch state', err)
print(err)
else:
for project in projects:
print(project.status())
Expand All @@ -141,19 +145,16 @@ def _validate_branches(local: bool, remote: bool, local_branch_exists: bool, rem
if local and remote:
branch_exists = local_branch_exists or remote_branch_exists
if not branch_exists:
cprint(' - No local or remote branches to prune\n', 'red')
raise ClowderError
raise ClowderError(ClowderErrorType.PRUNE_NO_BRANCHES, f' - No local or remote branches to prune')
print(' - Prune local and remote branches\n')
return

if remote:
if not remote_branch_exists:
cprint(' - No remote branches to prune\n', 'red')
raise ClowderError
raise ClowderError(ClowderErrorType.PRUNE_NO_BRANCHES, f' - No remote branches to prune')
print(' - Prune remote branches\n')
return

if not local_branch_exists:
print(' - No local branches to prune\n')
raise ClowderError
raise ClowderError(ClowderErrorType.PRUNE_NO_BRANCHES, f' - No local branches to prune')
print(' - Prune local branches\n')

0 comments on commit 62c64bc

Please sign in to comment.