Improve error output
This commit is contained in:
@@ -259,8 +259,7 @@ def build(options: BuildOptions) -> None:
|
|||||||
docker.copy_out(container_output_dir, options.output_dir)
|
docker.copy_out(container_output_dir, options.output_dir)
|
||||||
log.step_end()
|
log.step_end()
|
||||||
except subprocess.CalledProcessError as error:
|
except subprocess.CalledProcessError as error:
|
||||||
print(f'::error::{error}')
|
log.error(f'Command {error.cmd} failed with code {error.returncode}. {error.stdout}')
|
||||||
print(f'Command {error.cmd} failed with code {error.returncode}. {error.stdout}')
|
|
||||||
troubleshoot(options.package_dir, error)
|
troubleshoot(options.package_dir, error)
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
|
|||||||
+23
-8
@@ -1,7 +1,7 @@
|
|||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
import sys
|
import sys
|
||||||
from typing import Optional
|
from typing import Optional, Union
|
||||||
|
|
||||||
DEFAULT_FOLD_PATTERN = ('{name}', '')
|
DEFAULT_FOLD_PATTERN = ('{name}', '')
|
||||||
FOLD_PATTERNS = {
|
FOLD_PATTERNS = {
|
||||||
@@ -78,25 +78,39 @@ class Logger:
|
|||||||
def step(self, step_description: str):
|
def step(self, step_description: str):
|
||||||
self.step_end()
|
self.step_end()
|
||||||
self.step_start_time = time.time()
|
self.step_start_time = time.time()
|
||||||
self.start_fold_group(step_description)
|
self._start_fold_group(step_description)
|
||||||
|
|
||||||
def step_end(self):
|
def step_end(self, success=True):
|
||||||
if self.step_start_time is not None:
|
if self.step_start_time is not None:
|
||||||
self.end_fold_group()
|
self._end_fold_group()
|
||||||
c = self.colors
|
c = self.colors
|
||||||
duration = time.time() - self.step_start_time
|
duration = time.time() - self.step_start_time
|
||||||
print(f'{c.green}✓ {c.end}{duration:.2f}s'.rjust(78))
|
if success:
|
||||||
|
print(f'{c.green}✓ {c.end}{duration:.2f}s'.rjust(78))
|
||||||
|
else:
|
||||||
|
print(f'{c.red}✕ {c.end}{duration:.2f}s'.rjust(78))
|
||||||
|
|
||||||
self.step_start_time = None
|
self.step_start_time = None
|
||||||
|
|
||||||
def start_fold_group(self, name: str):
|
def error(self, error: Union[Exception, str]):
|
||||||
self.end_fold_group()
|
self.step_end(success=False)
|
||||||
|
print()
|
||||||
|
|
||||||
|
if self.fold_mode == 'github':
|
||||||
|
print(f'::error::{error}')
|
||||||
|
else:
|
||||||
|
c = self.colors
|
||||||
|
print(f'{c.bright_red}Error{c.end} {error}')
|
||||||
|
|
||||||
|
def _start_fold_group(self, name: str):
|
||||||
|
self._end_fold_group()
|
||||||
self.active_fold_group_name = name
|
self.active_fold_group_name = name
|
||||||
fold_start_pattern = FOLD_PATTERNS.get(self.fold_mode, DEFAULT_FOLD_PATTERN)[0]
|
fold_start_pattern = FOLD_PATTERNS.get(self.fold_mode, DEFAULT_FOLD_PATTERN)[0]
|
||||||
|
|
||||||
print(fold_start_pattern.format(name=self.active_fold_group_name))
|
print(fold_start_pattern.format(name=self.active_fold_group_name))
|
||||||
print()
|
print()
|
||||||
|
|
||||||
def end_fold_group(self):
|
def _end_fold_group(self):
|
||||||
if self.active_fold_group_name:
|
if self.active_fold_group_name:
|
||||||
fold_start_pattern = FOLD_PATTERNS.get(self.fold_mode, DEFAULT_FOLD_PATTERN)[1]
|
fold_start_pattern = FOLD_PATTERNS.get(self.fold_mode, DEFAULT_FOLD_PATTERN)[1]
|
||||||
print(fold_start_pattern.format(name=self.active_fold_group_name))
|
print(fold_start_pattern.format(name=self.active_fold_group_name))
|
||||||
@@ -142,6 +156,7 @@ class Colors():
|
|||||||
yellow = '\033[33m'
|
yellow = '\033[33m'
|
||||||
blue = '\033[34m'
|
blue = '\033[34m'
|
||||||
cyan = '\033[36m'
|
cyan = '\033[36m'
|
||||||
|
bright_red = '\033[91m'
|
||||||
bright_green = '\033[92m'
|
bright_green = '\033[92m'
|
||||||
white = '\033[37m\033[97m'
|
white = '\033[37m\033[97m'
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user