Skip to content

Conversation

spywo
Copy link

@spywo spywo commented Oct 2, 2025

The code and message should be able to return. It keeps consistent with the API of C++. The naming conversion is also followed with python PEP 8.

@spywo
Copy link
Author

spywo commented Oct 2, 2025

For example, C++

try {}
catch (const AdProjectionSystem::EAdProjectionSystemException& e) {
    // Handle error with code and message
    auto errorCode = e.getErrorCode();
    auto errorMessage = e.getErrorMessage();
    
    if (errorCode == ADPROJECTIONSYSTEM_ERROR_CRS_NOT_FOUND) {
        // Provide localized message or fallback behavior
    }
}

The python should also have the similiar way:

try:
except AdProjectionSystem.EAdProjectionSystemException as e:
    error_code = e.GetErrorCode()
    error_message = e.GetErrorMessage()
    
    # Use error code for localization or display message directly
    handle_error(error_code, error_message)

The code and message should be able to return. It keeps consistent with the API of C++. The naming conversion is also followed with ACT implementation rather than python PEP 8.
@spywo spywo force-pushed the oliver/python/exception-getter branch from 88540b0 to ae3285b Compare October 2, 2025 19:50
@spywo
Copy link
Author

spywo commented Oct 2, 2025

The other language also has the issue, like Java.

It ensures Cross-Language Consistency.
C++: Uses methods (getErrorCode())
C#: Uses properties (ErrorCode)
Java: Uses methods (getErrorCode())
Python: Can support both patterns

Meanwhile, rename the methods to comply with PEP 8
@gangatp gangatp requested a review from Copilot October 7, 2025 10:15
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds getter methods and properties to the Python exception class to provide consistent access to error information. The implementation aligns with C++ API patterns and follows Python PEP 8 naming conventions.

Key changes:

  • Added getter methods (get_error_code, get_error_message, get_error_name, get_error_description)
  • Added corresponding properties (error_code, error_message, error_name, error_description)
  • Implemented logic to map error codes to names and descriptions

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +179 to +184
w.Writeln(" return self.get_error_name()")
w.Writeln(" ")
w.Writeln(" @property")
w.Writeln(" def error_description(self):")
w.Writeln(" \"\"\"Property to access error description\"\"\"")
w.Writeln(" return self.get_error_description()")
Copy link
Preview

Copilot AI Oct 7, 2025

Choose a reason for hiding this comment

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

The properties error_name and error_description add unnecessary indirection by calling getter methods that contain the actual logic. Consider implementing the logic directly in the properties to eliminate the redundant method calls and simplify the code structure.

Suggested change
w.Writeln(" return self.get_error_name()")
w.Writeln(" ")
w.Writeln(" @property")
w.Writeln(" def error_description(self):")
w.Writeln(" \"\"\"Property to access error description\"\"\"")
w.Writeln(" return self.get_error_description()")
w.Writeln(" # Inlined logic from get_error_name")
w.Writeln(" return type(self).__name__")
w.Writeln(" ")
w.Writeln(" @property")
w.Writeln(" def error_description(self):")
w.Writeln(" \"\"\"Property to access error description\"\"\"")
w.Writeln(" # Inlined logic from get_error_description")
w.Writeln(" return str(self)")

Copilot uses AI. Check for mistakes.

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.

1 participant