All problems

Session cleanup masks the original bookbinding proof read error

Level 2 · node · Reliability · Cleanup exception masks a preceding operation exception

Scenario

A fictional bookbinding workshop opens an inspection session, reads proof data, and closes the session. Reading and closing can fail independently, and staff use the original operation error to diagnose inspection failures. When both operations fail, only the closing error is reported.

Requirements

After opening a session successfully, attempt one read and exactly one close regardless of the read outcome. If reading fails, throw the original Error object, even if closing also fails. If only closing fails after a successful read, throw the closing error. If both succeed, return the proof data. Propagate an opening failure unchanged without attempting to close. All errors are Error objects and the device is synchronous.

Acceptance criteria

  • Return the proof data and close the session once when reading and closing succeed.
  • Attempt one close even when reading fails and propagate the original read error object.
  • Propagate the original closing error when reading succeeds but closing fails.
  • When both reading and closing fail, do not replace the read error with the closing error.
  • Propagate an opening failure unchanged without calling read or close.