Skip to content

Report the offset of an input stream error - #380

Open
gennaroprota wants to merge 1 commit into
developfrom
feature/report-the-offset-of-an-input-stream-error
Open

Report the offset of an input stream error#380
gennaroprota wants to merge 1 commit into
developfrom
feature/report-the-offset-of-an-input-stream-error

Conversation

@gennaroprota

Copy link
Copy Markdown
Collaborator

archive_exception said only that the input failed, without giving a clue as to where the error occurred. It now names the offset at which the input went wrong, for text, binary and XML input archives alike.

`archive_exception` said only that the input failed, without giving a
clue as to where the error occurred.  It now names the offset at which
the input went wrong, for text, binary and XML input archives alike.
@robertramey

Copy link
Copy Markdown
Member

Note that the archive interface doesn't presume that an archive is a type of io stream. This opens the way to certain special purpose archives which might do something like implement a deep copy, calculate a CRC, etc, etc, There might be an example of such a custom archive in the documentation. Consider this when adding to stream behavior.

@gennaroprota

gennaroprota commented Aug 18, 2026

Copy link
Copy Markdown
Collaborator Author

Hmm, thanks for the heads-up. However, the archive interface is untouched: basic_iarchive, common_iarchive, interface_iarchive and archive_exception are all unchanged. The offset is produced in three places that already hold a stream or a stream buffer of their own:

  • basic_binary_iprimitive has std::basic_streambuf<Elem, Tr> & m_sb as a member.
  • basic_text_iprimitive<IStream> already needs a real stream for ios_flags_saver and basic_istream_locale_saver.
  • basic_xml_iarchive already needs get_is(), and the grammar calls get(), fail() and eof() on it. The two implementations return std::istream & and std::wistream &.

demo_trivial_archive.cpp, the example archive_reference.html points at, has a save_binary and no stream at all, and includes none of these headers. A CRC or deep copy archive would never reach this code, and if it threw archive_exception it would get the message it always got.

But one point is worth mentioning: an archive deriving from basic_xml_iarchive whose get_is() returned something stream-like but not a std::basic_istream would now fail to compile, since the offset comes from get_is().rdbuf(). Both in-tree implementations return real streams but, in general, this might break some code. What do you think?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants