Skip to content

Commit da5a2f9

Browse files
committed
Clarify confusing AssertionError when pending batch process disappears
- Clarify the batch submit process error messages. Previously, this was an AssertionError, whose text was presented to the user in a very confusing fashion. - Add debugging info to several asserts which assert for misconfiguration.
1 parent c0da1f3 commit da5a2f9

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

batchspawner/batchspawner.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,8 @@ def start(self):
344344
# be interrupted at the next yield, and self.stop() will be called.
345345
# So this function should not return unless successful, and if unsuccessful
346346
# should either raise and Exception or loop forever.
347-
assert len(self.job_id) > 0
347+
if len(self.job_id) == 0:
348+
raise RuntimeError("Jupyter batch job submission failure (no jobid in output)")
348349
while True:
349350
yield self.poll()
350351
if self.state_isrunning():
@@ -355,7 +356,9 @@ def start(self):
355356
else:
356357
self.log.warn('Job ' + self.job_id + ' neither pending nor running.\n' +
357358
self.job_status)
358-
assert self.state_ispending()
359+
raise RuntimeError('The Jupyter batch job has disappeared '
360+
' while pending in the queue or died immediately '
361+
' after starting.')
359362
yield gen.sleep(self.startup_poll_interval)
360363

361364
self.current_ip = self.state_gethost()
@@ -425,19 +428,19 @@ class BatchSpawnerRegexStates(BatchSpawnerBase):
425428
See Python docs: re.match.expand""").tag(config=True)
426429

427430
def state_ispending(self):
428-
assert self.state_pending_re
431+
assert self.state_pending_re, "Misconfigured: define state_running_re"
429432
if self.job_status and re.search(self.state_pending_re, self.job_status):
430433
return True
431434
else: return False
432435

433436
def state_isrunning(self):
434-
assert self.state_running_re
437+
assert self.state_running_re, "Misconfigured: define state_running_re"
435438
if self.job_status and re.search(self.state_running_re, self.job_status):
436439
return True
437440
else: return False
438441

439442
def state_gethost(self):
440-
assert self.state_exechost_re
443+
assert self.state_exechost_re, "Misconfigured: define state_exechost_re"
441444
match = re.search(self.state_exechost_re, self.job_status)
442445
if not match:
443446
self.log.error("Spawner unable to match host addr in job status: " + self.job_status)

batchspawner/tests/test_spawners.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def test_submit_failure(db, io_loop):
124124
spawner = new_spawner(db=db)
125125
assert spawner.get_state() == {}
126126
spawner.batch_submit_cmd = 'cat > /dev/null; true'
127-
with pytest.raises(AssertionError) as e_info:
127+
with pytest.raises(RuntimeError) as e_info:
128128
io_loop.run_sync(spawner.start, timeout=30)
129129
assert spawner.job_id == ''
130130
assert spawner.job_status == ''
@@ -133,7 +133,7 @@ def test_pending_fails(db, io_loop):
133133
spawner = new_spawner(db=db)
134134
assert spawner.get_state() == {}
135135
spawner.batch_query_cmd = 'echo xyz'
136-
with pytest.raises(AssertionError) as e_info:
136+
with pytest.raises(RuntimeError) as e_info:
137137
io_loop.run_sync(spawner.start, timeout=30)
138138
assert spawner.job_id == ''
139139
assert spawner.job_status == ''

0 commit comments

Comments
 (0)