Skip to content

fix: make VsagException public inherit from std::exception#1788

Open
inabao wants to merge 1 commit into0.18from
cp-1776-to-0.18
Open

fix: make VsagException public inherit from std::exception#1788
inabao wants to merge 1 commit into0.18from
cp-1776-to-0.18

Conversation

@inabao
Copy link
Copy Markdown
Collaborator

@inabao inabao commented Mar 31, 2026

Summary

Cherry-pick of PR #1776 to branch 0.18

  • Fix VsagException to use public inheritance from std::exception instead of private inheritance
  • Reorder catch blocks in engine.cpp to ensure VsagException is caught before std::exception
  • This allows VsagException to be caught by catch (std::exception& e) handlers, following standard C++ exception handling patterns

Problem

The class was using private inheritance (default for class):

class VsagException : std::exception {  // private inheritance

This prevented catching VsagException with std::exception handler, breaking standard exception handling.

Solution

Changed to public inheritance:

class VsagException : public std::exception {

And reordered catch blocks to ensure derived class (VsagException) is caught before base class (std::exception).

Changes

  1. src/vsag_exception.h: Changed to public inheritance
  2. src/factory/engine.cpp: Reordered catch blocks (VsagException before std::exception)

Impact

  • No breaking changes - all existing code behavior unchanged
  • Adds ability to catch VsagException via std::exception handler
  • Follows C++ standard practice for exception classes

The class was using private inheritance which prevented catching
VsagException with std::exception handler, breaking standard C++
exception handling patterns.

Signed-off-by: jinjiabao.jjb <jinjiabao.jjb@antgroup.com>
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request correctly updates the inheritance of VsagException to public and reorders the catch blocks in Engine::CreateIndex to ensure that the more specific VsagException is caught before the general std::exception. A review comment suggests optimizing the logging macro call to avoid unnecessary string concatenation by passing arguments separately.

LOG_ERROR_AND_RETURNS(
ErrorType::NO_ENOUGH_MEMORY, "failed to create index(not enough memory): ", e.what());
} catch (const vsag::VsagException& e) {
LOG_ERROR_AND_RETURNS(e.error_.type, "failed to create index: " + e.error_.message);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For consistency with other LOG_ERROR_AND_RETURNS calls in this file and to avoid an unnecessary temporary string allocation, you should pass the error message as a separate argument to the macro instead of using the + operator. The macro is variadic and handles concatenation internally using a stringstream.

Suggested change
LOG_ERROR_AND_RETURNS(e.error_.type, "failed to create index: " + e.error_.message);
LOG_ERROR_AND_RETURNS(e.error_.type, "failed to create index: ", e.error_.message);

@inabao inabao added kind/bug Something isn't working version/0.18 labels Mar 31, 2026
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 31, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

@@            Coverage Diff             @@
##             0.18    #1788      +/-   ##
==========================================
- Coverage   91.30%   91.10%   -0.21%     
==========================================
  Files         328      328              
  Lines       19340    19340              
==========================================
- Hits        17658    17619      -39     
- Misses       1682     1721      +39     
Flag Coverage Δ
cpp 91.10% <100.00%> (-0.21%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
common 85.81% <ø> (ø)
datacell 92.57% <ø> (-0.96%) ⬇️
index 90.92% <ø> (-0.10%) ⬇️
simd 100.00% <ø> (ø)

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3bdba6c...78fbcb4. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Collaborator

@LHT129 LHT129 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

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

Labels

kind/bug Something isn't working size/XS version/0.18

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants