Skip to content

Commit 5c4b167

Browse files
authored
Improve error messages in file_packager.py. (#17599)
The terms `not be under` and `is below` here were confusing/wrong I hink. This error is generated when files are "not contained within" the current working directory which in mind is the same as "not below". However the error message was using the term "below" to been "outside of" which seems wrong to me. Fixes: #2656
1 parent ba4c5f1 commit 5c4b167

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

test/test_other.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2723,13 +2723,13 @@ def check(text):
27232723
if empty_lines > 1:
27242724
self.fail('output contains more then one empty line in row')
27252725

2726-
# relative path to below the current dir is invalid
2726+
# relative path must be within/below the current dir
27272727
stderr = self.expect_fail([FILE_PACKAGER, 'test.data', '--preload', '../data1.txt'])
2728-
self.assertContained('below the current directory', stderr)
2728+
self.assertContained('which is not contained within the current directory', stderr)
27292729

27302730
# relative path that ends up under us is cool
27312731
proc = self.run_process([FILE_PACKAGER, 'test.data', '--preload', '../subdir/data2.txt'], stderr=PIPE, stdout=PIPE)
2732-
self.assertNotContained('below the current directory', proc.stderr)
2732+
self.assertNotContained('which is not contained within the current directory', proc.stderr)
27332733
check(proc.stdout)
27342734

27352735
# direct path leads to the same code being generated - relative path does not make us do anything different

tools/file_packager.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -477,27 +477,28 @@ def main():
477477
if not file_.explicit_dst_path:
478478
for file_ in data_files:
479479
# This file was not defined with src@dst, so we inferred the destination
480-
# from the source. In that case, we require that the destination not be
481-
# under the current location
480+
# from the source. In that case, we require that the destination be
481+
# within the current working directory.
482482
path = file_.dstpath
483483
# Use os.path.realpath to resolve any symbolic links to hard paths,
484484
# to match the structure in curr_abspath.
485485
abspath = os.path.realpath(os.path.abspath(path))
486486
if DEBUG:
487487
err(path, abspath, curr_abspath)
488488
if not abspath.startswith(curr_abspath):
489-
err('Error: Embedding "%s" which is below the current directory '
490-
'"%s". This is invalid since the current directory becomes the '
491-
'root that the generated code will see' % (path, curr_abspath))
489+
err('Error: Embedding "%s" which is not contained within the current directory '
490+
'"%s". This is invalid since the current directory becomes the '
491+
'root that the generated code will see. To include files outside of the current '
492+
'working directoty you can use the `--preload-file srcpath@dstpath` syntax to '
493+
'explicitly specify the target location.' % (path, curr_abspath))
492494
sys.exit(1)
493495
file_.dstpath = abspath[len(curr_abspath) + 1:]
494496
if os.path.isabs(path):
495497
err('Warning: Embedding an absolute file/directory name "%s" to the '
496498
'virtual filesystem. The file will be made available in the '
497-
'relative path "%s". You can use the explicit syntax '
498-
'--preload-file srcpath@dstpath to explicitly specify the target '
499-
'location the absolute source path should be directed to.'
500-
% (path, file_.dstpath))
499+
'relative path "%s". You can use the `--preload-file srcpath@dstpath` '
500+
'syntax to explicitly specify the target location the absolute source '
501+
'path should be directed to.' % (path, file_.dstpath))
501502

502503
for file_ in data_files:
503504
# name in the filesystem, native and emulated

0 commit comments

Comments
 (0)