Skip to content

Commit b4293f0

Browse files
committed
windows: raise a custom exception when static_replace_in_file fails
I knew I would come to regret use of sys.exit().
1 parent f2c183e commit b4293f0

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

cpython-windows/build.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,10 @@ def find_vctools_path():
213213
return tools_path
214214

215215

216+
class NoSearchStringError(Exception):
217+
"""Represents a missing search string when replacing content in a file."""
218+
219+
216220
def static_replace_in_file(p: pathlib.Path, search, replace):
217221
"""Replace occurrences of a string in a file.
218222
@@ -225,8 +229,7 @@ def static_replace_in_file(p: pathlib.Path, search, replace):
225229
# Build should be as deterministic as possible. Assert that wanted changes
226230
# actually occur.
227231
if search not in data:
228-
log("search string (%s) not in %s" % (search, p))
229-
sys.exit(1)
232+
raise NoSearchStringError("search string (%s) not in %s" % (search, p))
230233

231234
log("replacing `%s` with `%s` in %s" % (search, replace, p))
232235
data = data.replace(search, replace)

0 commit comments

Comments
 (0)