Skip to content

Commit 23657a4

Browse files
eyalitkijpakkane
authored andcommitted
Rewriter: Handle unknown write targets
Add error checks for cases in which the write target is unknown and ensure all error cases indeed abort the execution to avoid internal crash. Resolves #13502. Signed-off-by: Eyal Itkin <[email protected]>
1 parent 02bbe3e commit 23657a4

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

mesonbuild/rewriter.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -539,16 +539,21 @@ def process_kwargs(self, cmd: T.Dict[str, T.Any]) -> None:
539539
arg_node = node.args
540540
elif cmd['function'] == 'target':
541541
tmp_tgt = self.find_target(cmd['id'])
542-
if tmp_tgt:
543-
node = tmp_tgt.node
544-
arg_node = node.args
542+
if not tmp_tgt:
543+
mlog.error('Unable to find the target', mlog.bold(cmd['id']), *self.on_error())
544+
return self.handle_error()
545+
node = tmp_tgt.node
546+
arg_node = node.args
545547
elif cmd['function'] == 'dependency':
546548
tmp_dep = self.find_dependency(cmd['id'])
547-
if tmp_dep:
548-
node = tmp_dep.node
549-
arg_node = node.args
549+
if not tmp_dep:
550+
mlog.error('Unable to find the dependency', mlog.bold(cmd['id']), *self.on_error())
551+
return self.handle_error()
552+
node = tmp_dep.node
553+
arg_node = node.args
550554
if not node:
551-
mlog.error('Unable to find the function node')
555+
mlog.error('Unable to find the function node', *self.on_error())
556+
return self.handle_error()
552557
assert isinstance(node, FunctionNode)
553558
assert isinstance(arg_node, ArgumentNode)
554559
# Transform the key nodes to plain strings

0 commit comments

Comments
 (0)