84 def _to_match_disk_impl(self, sub: str, is_todo: bool) -> T:
85 call = recordCall(False)
86 system = _selfieSystem()
87 if system.mode.can_write(is_todo, call, system):
88 actual = self.generator()
89 self.disk.write_disk(
90 Snapshot.of(self.roundtrip.serialize(actual)), sub, call
91 )
92 if is_todo:
93 system.write_inline(TodoStub.to_match_disk.create_literal(), call)
94 return actual
95 else:
96 if is_todo:
97 raise Exception("Can't call `to_match_disk_todo` in readonly mode!")
98 else:
99 snapshot = self.disk.read_disk(sub, call)
100 if snapshot is None:
101 raise Exception(system.mode.msg_snapshot_not_found())
102 if snapshot.subject.is_binary or len(snapshot.facets) > 0:
103 raise Exception(
104 f"Expected a string subject with no facets, got {snapshot}"
105 )
106 return self.roundtrip.parse(snapshot.subject.value_string())
107