diff --git a/cpp/src/parquet/arrow/arrow_reader_writer_test.cc b/cpp/src/parquet/arrow/arrow_reader_writer_test.cc index 27a1cef30872e..3c69184b5cc07 100644 --- a/cpp/src/parquet/arrow/arrow_reader_writer_test.cc +++ b/cpp/src/parquet/arrow/arrow_reader_writer_test.cc @@ -5225,16 +5225,17 @@ TEST(TestArrowReadWrite, OperationsOnClosedWriter) { // Operations on closed writer are incorrect. However, should not segfault ASSERT_OK(writer->Close()); - EXPECT_THROW_THAT( - [&]() { ASSERT_OK(writer->WriteTable(*table, 1)); }, ParquetException, - ::testing::Property(&ParquetException::what, - ::testing::HasSubstr("Cannot do operation on closed file"))); + EXPECT_THROW_THAT([&]() { ASSERT_OK(writer->WriteTable(*table, 1)); }, ParquetException, + ::testing::Property( + &ParquetException::what, + ::testing::HasSubstr("Cannot get properties from closed file"))); // These two functions do not throw because they use PARQUET_CATCH_NOT_OK // in their implementations. - ASSERT_RAISES_WITH_MESSAGE(IOError, "IOError: Cannot do operation on closed file", + ASSERT_RAISES_WITH_MESSAGE(IOError, + "IOError: Cannot append buffered-row-group to closed file", writer->NewBufferedRowGroup()); - ASSERT_RAISES_WITH_MESSAGE(IOError, "IOError: Cannot do operation on closed file", + ASSERT_RAISES_WITH_MESSAGE(IOError, "IOError: Cannot append row-group to closed file", writer->NewRowGroup(1)); } diff --git a/cpp/src/parquet/file_writer.cc b/cpp/src/parquet/file_writer.cc index edf9f243305b9..a94b26e5531bd 100644 --- a/cpp/src/parquet/file_writer.cc +++ b/cpp/src/parquet/file_writer.cc @@ -635,12 +635,12 @@ void ParquetFileWriter::Close() { } RowGroupWriter* ParquetFileWriter::AppendRowGroup() { - AssertNotClosed(); + AssertNotClosed("Cannot append row-group to closed file"); return contents_->AppendRowGroup(); } RowGroupWriter* ParquetFileWriter::AppendBufferedRowGroup() { - AssertNotClosed(); + AssertNotClosed("Cannot append buffered-row-group to closed file"); return contents_->AppendBufferedRowGroup(); } @@ -650,18 +650,18 @@ RowGroupWriter* ParquetFileWriter::AppendRowGroup(int64_t num_rows) { void ParquetFileWriter::AddKeyValueMetadata( const std::shared_ptr& key_value_metadata) { - AssertNotClosed(); + AssertNotClosed("Cannot add key-value metadata to closed file"); contents_->AddKeyValueMetadata(key_value_metadata); } const std::shared_ptr& ParquetFileWriter::properties() const { - AssertNotClosed(); + AssertNotClosed("Cannot get properties from closed file"); return contents_->properties(); } -void ParquetFileWriter::AssertNotClosed() const { +void ParquetFileWriter::AssertNotClosed(std::string_view message) const { if (contents_ == nullptr) { - throw ParquetException("Cannot do operation on closed file"); + throw ParquetException(message); } } diff --git a/cpp/src/parquet/file_writer.h b/cpp/src/parquet/file_writer.h index 1ed03e55417d6..5ad640a597cb4 100644 --- a/cpp/src/parquet/file_writer.h +++ b/cpp/src/parquet/file_writer.h @@ -249,7 +249,7 @@ class PARQUET_EXPORT ParquetFileWriter { const std::shared_ptr metadata() const; /// Verify file is not closed. - void AssertNotClosed() const; + void AssertNotClosed(std::string_view message) const; private: // Holds a pointer to an instance of Contents implementation