FAILURE MAP
← Case archive

FA-5271 / Exception flow / Open access

Finally return precedence: Refuses to let a finally return suppress a pending exception · case 01

Refuses to let a finally return suppress a pending exception and changes the required Python-language result.

Verified by executionVariant 1 · 6 checks per implementationDownload source bundle ↓JSON ↗

ROOT CAUSE

Refuses to let a finally return suppress a pending exception. The executable reproducer isolates this operation from the rest of the contract.

VERIFIED REPAIR

Run cleanup for both body returns and exceptions. Only when override is true does a finally return replace the pending body result or suppress its ValueError; otherwise preserve the pending outcome.

Unsuccessful approach: The alternative still fails because it conditions finally replacement on payload truthiness.

Case contract

Run cleanup for both body returns and exceptions. Only when override is true does a finally return replace the pending body result or suppress its ValueError; otherwise preserve the pending outcome. Inputs use the finite Python types shown in the fixtures. An error string denotes the specified caught exception, not an unhandled process failure.

Why this case matters

Runs Python standard-library language operations in a deterministic local reproducer. Literal expected answers are authored independently. Related defects share an evaluation group to avoid benchmark split leakage.

1 / The failure

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(value, error, override):
    log=[]
    def f():
        try:
            log.append('try')
            if error: raise ValueError('body')
            return ['body',value]
        finally:
            log.append('finally')
            if override and not error: return ['cleanup',value]
    try: result=f()
    except ValueError: result='ValueError'
    return [result,log]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('ordinary body result', solve('x', False, False), [['body', 'x'], ['try', 'finally']])
check('body error preserved', solve('x', True, False), ['ValueError', ['try', 'finally']])
check('cleanup replaces successful result', solve('x', False, True), [['cleanup', 'x'], ['try', 'finally']])
check('cleanup suppresses body error', solve('x', True, True), [['cleanup', 'x'], ['try', 'finally']])
check('zero cleanup return valid', solve(0, True, True), [['cleanup', 0], ['try', 'finally']])
check('None cleanup return valid', solve(None, False, True), [['cleanup', None], ['try', 'finally']])
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
Boundary fixtureActualExpectedOutcome
ordinary body result[['body', 'x'], ['try', 'finally']][['body', 'x'], ['try', 'finally']]Passed
body error preserved['ValueError', ['try', 'finally']]['ValueError', ['try', 'finally']]Passed
cleanup replaces successful result[['cleanup', 'x'], ['try', 'finally']][['cleanup', 'x'], ['try', 'finally']]Passed
cleanup suppresses body error['ValueError', ['try', 'finally']][['cleanup', 'x'], ['try', 'finally']]Failed
zero cleanup return valid['ValueError', ['try', 'finally']][['cleanup', 0], ['try', 'finally']]Failed
None cleanup return valid[['cleanup', None], ['try', 'finally']][['cleanup', None], ['try', 'finally']]Passed

SHA-256 / fd8bffbb93fed006c26a66a569571b915c15631454a399174e379d489f4c9b6a

2 / The unsuccessful fix

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(value, error, override):
    log=[]
    def f():
        try:
            log.append('try')
            if error: raise ValueError('body')
            return ['body',value]
        finally:
            log.append('finally')
            if override and value: return ['cleanup',value]
    try: result=f()
    except ValueError: result='ValueError'
    return [result,log]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('ordinary body result', solve('x', False, False), [['body', 'x'], ['try', 'finally']])
check('body error preserved', solve('x', True, False), ['ValueError', ['try', 'finally']])
check('cleanup replaces successful result', solve('x', False, True), [['cleanup', 'x'], ['try', 'finally']])
check('cleanup suppresses body error', solve('x', True, True), [['cleanup', 'x'], ['try', 'finally']])
check('zero cleanup return valid', solve(0, True, True), [['cleanup', 0], ['try', 'finally']])
check('None cleanup return valid', solve(None, False, True), [['cleanup', None], ['try', 'finally']])
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
Boundary fixtureActualExpectedOutcome
ordinary body result[['body', 'x'], ['try', 'finally']][['body', 'x'], ['try', 'finally']]Passed
body error preserved['ValueError', ['try', 'finally']]['ValueError', ['try', 'finally']]Passed
cleanup replaces successful result[['cleanup', 'x'], ['try', 'finally']][['cleanup', 'x'], ['try', 'finally']]Passed
cleanup suppresses body error[['cleanup', 'x'], ['try', 'finally']][['cleanup', 'x'], ['try', 'finally']]Passed
zero cleanup return valid['ValueError', ['try', 'finally']][['cleanup', 0], ['try', 'finally']]Failed
None cleanup return valid[['body', None], ['try', 'finally']][['cleanup', None], ['try', 'finally']]Failed

SHA-256 / c05d26c3abfd118a8e8701435dc4af88ace7ca3c9400b67372b4598d259b6a3c

3 / The verified repair

Exit 0
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(value, error, override):
    log=[]
    def f():
        try:
            log.append('try')
            if error: raise ValueError('body')
            return ['body',value]
        finally:
            log.append('finally')
            if override: return ['cleanup',value]
    try: result=f()
    except ValueError: result='ValueError'
    return [result,log]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('ordinary body result', solve('x', False, False), [['body', 'x'], ['try', 'finally']])
check('body error preserved', solve('x', True, False), ['ValueError', ['try', 'finally']])
check('cleanup replaces successful result', solve('x', False, True), [['cleanup', 'x'], ['try', 'finally']])
check('cleanup suppresses body error', solve('x', True, True), [['cleanup', 'x'], ['try', 'finally']])
check('zero cleanup return valid', solve(0, True, True), [['cleanup', 0], ['try', 'finally']])
check('None cleanup return valid', solve(None, False, True), [['cleanup', None], ['try', 'finally']])
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
Boundary fixtureActualExpectedOutcome
ordinary body result[['body', 'x'], ['try', 'finally']][['body', 'x'], ['try', 'finally']]Passed
body error preserved['ValueError', ['try', 'finally']]['ValueError', ['try', 'finally']]Passed
cleanup replaces successful result[['cleanup', 'x'], ['try', 'finally']][['cleanup', 'x'], ['try', 'finally']]Passed
cleanup suppresses body error[['cleanup', 'x'], ['try', 'finally']][['cleanup', 'x'], ['try', 'finally']]Passed
zero cleanup return valid[['cleanup', 0], ['try', 'finally']][['cleanup', 0], ['try', 'finally']]Passed
None cleanup return valid[['cleanup', None], ['try', 'finally']][['cleanup', None], ['try', 'finally']]Passed

SHA-256 / c35012e2df31e8a798260f34a59fbdff64b11683c2cb79dc7034349f6341d4c6

Verification & scope

This reproducer isolates one failure mechanism. Results cover the supplied fixtures. Variants within a family share a test contract and should remain grouped when constructing evaluation splits. Related mechanisms with a shared evaluation_group must also remain together; these controlled models are not independent production incidents.

Observations recorded using Python 3.12.14 at 2026-09-29T14:37:47.861945+00:00.

Case digest / b0175fcb492c0b363a0f2c01f6dee0678ca38544160d69fdd2e9afaabcef9ce4