]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/tools/build/src/build/errors.py
1 # Status: being written afresh by Vladimir Prus
3 # Copyright 2007 Vladimir Prus
4 # Distributed under the Boost Software License, Version 1.0.
5 # (See accompanying file LICENSE.txt or https://www.bfgroup.xyz/b2/LICENSE.txt)
7 # This file is supposed to implement error reporting for Boost.Build.
8 # Experience with jam version has shown that printing full backtrace
9 # on each error is buffling. Further, for errors printed after parsing --
10 # during target building, the stacktrace does not even mention what
11 # target is being built.
13 # This module implements explicit contexts -- where other code can
14 # communicate which projects/targets are being built, and error
15 # messages will show those contexts. For programming errors,
16 # Python assertions are to be used.
22 def format(message
, prefix
=""):
23 parts
= str(message
).split("\n")
24 return "\n".join(prefix
+p
for p
in parts
)
29 def __init__(self
, message
, nested
=None):
30 self
.message_
= message
33 def report(self
, indent
=""):
34 print indent
+ " -", self
.message_
36 print indent
+ " declared at:"
37 for n
in self
.nested_
:
38 n
.report(indent
+ " ")
43 raw
= bjam
.backtrace()
46 def report(self
, indent
=""):
48 print indent
+ " - %s:%s" % (r
[0], r
[1])
50 class ExceptionWithUserContext(Exception):
52 def __init__(self
, message
, context
,
53 original_exception
=None, original_tb
=None, stack
=None):
54 Exception.__init
__(self
, message
)
55 self
.context_
= context
56 self
.original_exception_
= original_exception
57 self
.original_tb_
= original_tb
61 print "error:", self
.args
[0]
62 if self
.original_exception_
:
63 print format(str(self
.original_exception_
), " ")
65 print " error context (most recent first):"
66 for c
in self
.context_
[::-1]:
69 if "--stacktrace" in bjam
.variable("ARGV"):
71 traceback
.print_tb(self
.original_tb_
)
73 for l
in traceback
.format_list(self
.stack_
):
76 print " use the '--stacktrace' option to get Python stacktrace"
79 def user_error_checkpoint(callable):
80 def wrapper(self
, *args
):
81 errors
= self
.manager().errors()
83 return callable(self
, *args
)
84 except ExceptionWithUserContext
, e
:
87 errors
.handle_stray_exception(e
)
89 errors
.pop_user_context()
102 def push_user_context(self
, message
, nested
=None):
103 self
.contexts_
.append(Context(message
, nested
))
105 def pop_user_context(self
):
106 del self
.contexts_
[-1]
108 def push_jamfile_context(self
):
109 self
.contexts_
.append(JamfileContext())
111 def pop_jamfile_context(self
):
112 del self
.contexts_
[-1]
114 def capture_user_context(self
):
115 return self
.contexts_
[:]
117 def handle_stray_exception(self
, e
):
118 raise ExceptionWithUserContext("unexpected exception", self
.contexts_
[:],
119 e
, sys
.exc_info()[2])
120 def __call__(self
, message
):
121 self
._count
= self
._count
+ 1
122 raise ExceptionWithUserContext(message
, self
.contexts_
[:],
123 stack
=traceback
.extract_stack())
126 def nearest_user_location():
129 tuple: the filename and line number of the nearest user location
131 bt
= bjam
.backtrace()
135 return last
[0], last
[1]