1#!/usr/bin/env python 2# encoding: utf-8 3# Thomas Nagy, 2010-2018 (ita) 4 5""" 6Exceptions used in the Waf code 7""" 8 9import traceback, sys 10 11class WafError(Exception): 12 """Base class for all Waf errors""" 13 def __init__(self, msg='', ex=None): 14 """ 15 :param msg: error message 16 :type msg: string 17 :param ex: exception causing this error (optional) 18 :type ex: exception 19 """ 20 Exception.__init__(self) 21 self.msg = msg 22 assert not isinstance(msg, Exception) 23 24 self.stack = [] 25 if ex: 26 if not msg: 27 self.msg = str(ex) 28 if isinstance(ex, WafError): 29 self.stack = ex.stack 30 else: 31 self.stack = traceback.extract_tb(sys.exc_info()[2]) 32 self.stack += traceback.extract_stack()[:-1] 33 self.verbose_msg = ''.join(traceback.format_list(self.stack)) 34 35 def __str__(self): 36 return str(self.msg) 37 38class BuildError(WafError): 39 """Error raised during the build and install phases""" 40 def __init__(self, error_tasks=[]): 41 """ 42 :param error_tasks: tasks that could not complete normally 43 :type error_tasks: list of task objects 44 """ 45 self.tasks = error_tasks 46 WafError.__init__(self, self.format_error()) 47 48 def format_error(self): 49 """Formats the error messages from the tasks that failed""" 50 lst = ['Build failed'] 51 for tsk in self.tasks: 52 txt = tsk.format_error() 53 if txt: 54 lst.append(txt) 55 return '\n'.join(lst) 56 57class ConfigurationError(WafError): 58 """Configuration exception raised in particular by :py:meth:`waflib.Context.Context.fatal`""" 59 pass 60 61class TaskRescan(WafError): 62 """Task-specific exception type signalling required signature recalculations""" 63 pass 64 65class TaskNotReady(WafError): 66 """Task-specific exception type signalling that task signatures cannot be computed""" 67 pass 68 69