Merge pull request #103 from nix-community/logging

cleaner eval error messages
This commit is contained in:
Jörg Thalheim 2019-01-02 18:16:16 +01:00 committed by GitHub
commit 3cec008463
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 7 deletions

View file

@ -4,7 +4,7 @@ The following points apply when adding a new repository to repos.json
- [ ] By including this repository in NUR I give permission to license the
content under the MIT license.
Clarifiction where license should apply:
Clarification where license should apply:
The license above does not apply to the packages built by the
Nix Packages collection, merely to the package descriptions (i.e., Nix
expressions, build scripts, etc.). It also might not apply to patches

View file

@ -1,19 +1,29 @@
import argparse
import logging
import sys
from typing import List
from .combine import combine_command
from .format_manifest import format_manifest_command
from .index import index_command
from .update import update_command
from .path import ROOT
from .update import update_command
from .combine import combine_command
LOG_LEVELS = dict(
debug=logging.DEBUG,
info=logging.INFO,
error=logging.ERROR,
critical=logging.CRITICAL,
)
def parse_arguments(argv: List[str]) -> argparse.Namespace:
parser = argparse.ArgumentParser(
prog=argv[0], description="nur management commands"
)
parser.add_argument(
"--log-level", type=str, default="debug", choices=list(LOG_LEVELS.keys())
)
subparsers = parser.add_subparsers(description="subcommands")
@ -48,4 +58,6 @@ def parse_arguments(argv: List[str]) -> argparse.Namespace:
def main() -> None:
args = parse_arguments(sys.argv)
logging.basicConfig(level=LOG_LEVELS[args.log_level])
args.func(args)

View file

@ -1,2 +1,6 @@
class NurError(Exception):
pass
class EvalError(NurError):
pass

View file

@ -5,7 +5,7 @@ import tempfile
from argparse import Namespace
from pathlib import Path
from .error import NurError
from .error import EvalError
from .manifest import Repo, load_manifest, update_lock_file
from .path import EVALREPO_PATH, LOCK_PATH, MANIFEST_PATH, nixpkgs_path
from .prefetch import prefetch
@ -55,9 +55,9 @@ import {EVALREPO_PATH} {{
try:
res = proc.wait(5)
except subprocess.TimeoutExpired:
raise NurError(f"evaluation for {repo.name} timed out of after 5 seconds")
raise EvalError(f"evaluation for {repo.name} timed out of after 5 seconds")
if res != 0:
raise NurError(f"{repo.name} does not evaluate:\n$ {' '.join(cmd)}")
raise EvalError(f"{repo.name} does not evaluate:\n$ {' '.join(cmd)}")
def update(repo: Repo) -> Repo:
@ -71,15 +71,21 @@ def update(repo: Repo) -> Repo:
def update_command(args: Namespace) -> None:
logging.basicConfig(level=logging.INFO)
manifest = load_manifest(MANIFEST_PATH, LOCK_PATH)
for repo in manifest.repos:
try:
update(repo)
except Exception:
except EvalError as e:
if repo.locked_version is None:
# likely a repository added in a pull request, make it fatal then
raise
# Do not print stack traces
logger.error(f"repository {repo.name} failed to evaluate: {e}")
except Exception:
# for non-evaluation errors we want the stack trace
logger.exception(f"Failed to updated repository {repo.name}")
update_lock_file(manifest.repos, LOCK_PATH)