Skip to content

Commit 63014de

Browse files
gregmagolanalexeagle
authored andcommitted
chore: cleanup fail msgs with substitutions for cleaner error logs
1 parent 5a39b1f commit 63014de

File tree

5 files changed

+22
-14
lines changed

5 files changed

+22
-14
lines changed

lib/private/directory_path.bzl

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ DirectoryPathInfo = provider(
1414

1515
def _directory_path(ctx):
1616
if not ctx.file.directory.is_directory:
17-
fail("expected directory to be a TreeArtifact (ctx.actions.declare_directory) but got {}".format(ctx.file.directory))
17+
msg = "expected directory to be a TreeArtifact (ctx.actions.declare_directory) but got {}".format(ctx.file.directory)
18+
fail(msg)
1819
return [DirectoryPathInfo(path = ctx.attr.path, directory = ctx.file.directory)]
1920

2021
directory_path = rule(

lib/private/patch.bzl

+6-6
Original file line numberDiff line numberDiff line change
@@ -137,18 +137,18 @@ def patch(ctx, patches = None, patch_cmds = None, patch_cmds_win = None, patch_t
137137
)
138138
st = ctx.execute([bash_exe, "-c", command], working_directory = patch_directory)
139139
if st.return_code:
140-
fail("Error applying patch %s:\n%s%s" %
141-
(str(patchfile), st.stderr, st.stdout))
140+
msg = "Error applying patch {}:\n{}{}".format(str(patchfile), st.stderr, st.stdout)
141+
fail(msg)
142142

143143
if repo_utils.is_windows(ctx) and patch_cmds_win:
144144
for cmd in patch_cmds_win:
145145
st = ctx.execute([powershell_exe, "/c", cmd], working_directory = patch_directory)
146146
if st.return_code:
147-
fail("Error applying patch command %s:\n%s%s" %
148-
(cmd, st.stdout, st.stderr))
147+
msg = "Error applying patch command {}:\n{}{}".format(cmd, st.stdout, st.stderr)
148+
fail(msg)
149149
else:
150150
for cmd in patch_cmds:
151151
st = ctx.execute([bash_exe, "-c", cmd], working_directory = patch_directory)
152152
if st.return_code:
153-
fail("Error applying patch command %s:\n%s%s" %
154-
(cmd, st.stdout, st.stderr))
153+
msg = "Error applying patch command {}:\n{}{}".format(cmd, st.stdout, st.stderr)
154+
fail(msg)

lib/private/paths.bzl

+4-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ def _relative_file(to_file, frm_file):
2020
return to_file
2121

2222
if to_segments[0] != frm_segments[0]:
23-
fail("paths must share a common root, got '%s' and '%s'" % (to_file, frm_file))
23+
msg = "paths must share a common root, got '{}' and '{}'".format(to_file, frm_file)
24+
fail(msg)
2425

2526
longest_common = []
2627
for to_seg, frm_seg in zip(to_segments, frm_segments):
@@ -32,7 +33,8 @@ def _relative_file(to_file, frm_file):
3233
split_point = len(longest_common)
3334

3435
if split_point == 0:
35-
fail("paths share no common ancestor, '%s' -> '%s'" % (frm_file, to_file))
36+
msg = "paths share no common ancestor, '{}' -> '{}'".format(frm_file, to_file)
37+
fail(msg)
3638

3739
return _spaths.join(
3840
*(

lib/private/utils.bzl

+2-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ def _to_label(param):
6868
elif param_type == "Label":
6969
return param
7070
else:
71-
fail("Expected 'string' or 'Label' but got '%s'" % param_type)
71+
msg = "Expected 'string' or 'Label' but got '{}'".format(param_type)
72+
fail(msg)
7273

7374
def _is_external_label(param):
7475
"""Returns True if the given Label (or stringy version of a label) represents a target outside of the workspace

lib/private/write_source_file.bzl

+8-4
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,11 @@ def write_source_file(
4444
out_file = utils.to_label(out_file)
4545

4646
if utils.is_external_label(out_file):
47-
fail("out file %s must be in the user workspace" % out_file)
47+
msg = "out file {} must be in the user workspace".format(out_file)
48+
fail(msg)
4849
if out_file.package != native.package_name():
49-
fail("out file %s (in package '%s') must be a source file within the target's package: '%s'" % (out_file, out_file.package, native.package_name()))
50+
msg = "out file {} (in package '{}') must be a source file within the target's package: '{}'".format(out_file, out_file.package, native.package_name())
51+
fail(msg)
5052

5153
_write_source_file(
5254
name = name,
@@ -264,11 +266,13 @@ def _write_source_file_impl(ctx):
264266
])
265267
runfiles.append(ctx.attr.in_file[DirectoryPathInfo].directory)
266268
elif len(ctx.files.in_file) == 0:
267-
fail("in file %s must provide files" % ctx.attr.in_file.label)
269+
msg = "in file {} must provide files".format(ctx.attr.in_file.label)
270+
fail(msg)
268271
elif len(ctx.files.in_file) == 1:
269272
in_path = ctx.files.in_file[0].short_path
270273
else:
271-
fail("in file %s must be a single file or a target that provides DefaultOutputPathInfo or DirectoryPathInfo" % ctx.attr.in_file.label)
274+
msg = "in file {} must be a single file or a target that provides DefaultOutputPathInfo or DirectoryPathInfo".format(ctx.attr.in_file.label)
275+
fail(msg)
272276

273277
out_path = "/".join([ctx.label.package, ctx.attr.out_file]) if ctx.label.package else ctx.attr.out_file
274278
paths.append((in_path, out_path))

0 commit comments

Comments
 (0)