Skip to content

Commit b1576dd

Browse files
committed
Get rid of raising exceptions entirely
In favor of just returning status for uniform behavior
1 parent b799776 commit b1576dd

File tree

7 files changed

+21
-34
lines changed

7 files changed

+21
-34
lines changed

SCons/Action.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1454,16 +1454,6 @@ def execute(self, target, source, env, executor: Optional[ExecutorType] = None):
14541454
except TypeError:
14551455
result.command=self.strfunction(target, source, env)
14561456

1457-
# FIXME: This maintains backward compatibility with respect to
1458-
# which type of exceptions were returned by raising an
1459-
# exception and which ones were returned by value. It would
1460-
# probably be best to always return them by value here, but
1461-
# some codes do not check the return value of Actions and I do
1462-
# not have the time to modify them at this point.
1463-
if (exc_info[1] and
1464-
not isinstance(exc_info[1], SCons.Errors.SConsEnvironmentError)):
1465-
raise result
1466-
14671457
return result
14681458
finally:
14691459
# Break the cycle between the traceback object and this

SCons/CacheDirTests.py

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ def __setitem__(self, name, value) -> None:
164164
# so that _readconfig* will try to rewrite it
165165
old_config = os.path.join(self._CacheDir.path, "config")
166166
os.remove(old_config)
167-
167+
168168
try:
169169
self._CacheDir._readconfig(self._CacheDir.path)
170170
assert False, "Should have raised exception and did not"
@@ -315,23 +315,17 @@ def mkdir(dir, mode: int=0) -> None:
315315
old_warn_exceptions = SCons.Warnings.warningAsException(1)
316316
SCons.Warnings.enableWarningClass(SCons.Warnings.CacheWriteErrorWarning)
317317

318-
try:
319-
cd_f7 = self.test.workpath("cd.f7")
320-
self.test.write(cd_f7, "cd.f7\n")
321-
f7 = self.File(cd_f7, 'f7_bsig')
322-
323-
warn_caught = 0
324-
try:
325-
f7.push_to_cache()
326-
except SCons.Errors.BuildError as e:
327-
assert e.exc_info[0] == SCons.Warnings.CacheWriteErrorWarning
328-
warn_caught = 1
329-
assert warn_caught
330-
finally:
331-
shutil.copy2 = save_copy2
332-
os.mkdir = save_mkdir
333-
SCons.Warnings.warningAsException(old_warn_exceptions)
334-
SCons.Warnings.suppressWarningClass(SCons.Warnings.CacheWriteErrorWarning)
318+
cd_f7 = self.test.workpath("cd.f7")
319+
self.test.write(cd_f7, "cd.f7\n")
320+
f7 = self.File(cd_f7, 'f7_bsig')
321+
322+
warn_caught = 0
323+
r = f7.push_to_cache()
324+
assert r.exc_info[0] == SCons.Warnings.CacheWriteErrorWarning
325+
shutil.copy2 = save_copy2
326+
os.mkdir = save_mkdir
327+
SCons.Warnings.warningAsException(old_warn_exceptions)
328+
SCons.Warnings.suppressWarningClass(SCons.Warnings.CacheWriteErrorWarning)
335329

336330
def test_no_strfunction(self) -> None:
337331
"""Test handling no strfunction() for an action."""

SCons/Node/FS.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2999,7 +2999,7 @@ def _createDir(self) -> None:
29992999
# created.
30003000
self.dir._create()
30013001

3002-
def push_to_cache(self) -> None:
3002+
def push_to_cache(self) -> bool:
30033003
"""Try to push the node into a cache
30043004
"""
30053005
# This should get called before the Nodes' .built() method is
@@ -3010,10 +3010,10 @@ def push_to_cache(self) -> None:
30103010
# the node to cache so that the memoization of the self.exists()
30113011
# return value doesn't interfere.
30123012
if self.nocache:
3013-
return
3013+
return None
30143014
self.clear_memoized_values()
30153015
if self.exists():
3016-
self.get_build_env().get_CacheDir().push(self)
3016+
return self.get_build_env().get_CacheDir().push(self)
30173017

30183018
def retrieve_from_cache(self) -> bool:
30193019
"""Try to retrieve the node's content from a cache

SCons/Node/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,7 @@ def reset_executor(self) -> None:
678678
except AttributeError:
679679
pass
680680

681-
def push_to_cache(self) -> None:
681+
def push_to_cache(self) -> bool:
682682
"""Try to push a node into a cache
683683
"""
684684
pass

SCons/SConfTests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ def is_up_to_date(self) -> bool:
207207
return False
208208
def prepare(self) -> None:
209209
pass
210-
def push_to_cache(self) -> None:
210+
def push_to_cache(self) -> bool:
211211
pass
212212
def retrieve_from_cache(self) -> bool:
213213
return False

SCons/Taskmaster/TaskmasterTests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def targets(self, node):
7272
def disambiguate(self):
7373
return self
7474

75-
def push_to_cache(self) -> None:
75+
def push_to_cache(self) -> bool:
7676
pass
7777

7878
def retrieve_from_cache(self) -> bool:

SCons/Variables/PathVariable.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ def PathIsDirCreate(key, val, env) -> None:
109109
except PermissionError:
110110
m = 'Path for option %s could not be created: %s'
111111
raise SCons.Errors.UserError(m % (key, val))
112+
except OSError:
113+
m = 'Path for option %s could not be created: %s'
114+
raise SCons.Errors.UserError(m % (key, val))
112115

113116
@staticmethod
114117
def PathIsFile(key, val, env) -> None:

0 commit comments

Comments
 (0)