Skip to content

Conversation

@robfrank
Copy link
Collaborator

This pull request introduces a new standardized exception handling framework for ArcadeDB, focused on providing structured error codes, improved diagnostics, and better API response formatting. The changes include a major refactoring of the base exception class, the introduction of an ErrorCode enum for categorizing and identifying errors, and the addition of a specialized DatabaseException class. These updates enable more consistent error handling, easier troubleshooting, and better integration with HTTP APIs.

Exception Framework Refactor and Enhancements:

  • Refactored the base ArcadeDBException class to be abstract and to support standardized error codes, diagnostic context, JSON serialization for API responses, HTTP status code mapping, and timestamp tracking. Also added method chaining for context and improved string representation. Legacy constructors are retained for backward compatibility but marked as deprecated.
  • Introduced the ErrorCode enum, providing a comprehensive and categorized list of error codes for all major error domains (Database, Transaction, Query, Security, Storage, Network, Schema, Index, Graph, Import/Export, Internal). Each error code includes a numeric value, default message, and category, with utility methods for lookup and formatting.

Specialized Exception Classes:

  • Added a new DatabaseException class that extends ArcadeDBException, tailored for database lifecycle and operation errors. This class sets a default error code, provides constructors for error code/message/cause, and overrides HTTP status mapping for common database errors (e.g., 404 for not found, 409 for conflict).

@robfrank robfrank linked an issue Dec 17, 2025 that may be closed by this pull request
4 tasks
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @robfrank, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly overhauls ArcadeDB's exception handling mechanism to bring consistency, clarity, and better diagnostic capabilities. The core objective is to move away from disparate exception types towards a unified, code-driven system that not only simplifies error identification for developers but also provides richer, structured error responses for API consumers. This foundational change aims to improve the overall robustness, maintainability, and observability of the system.

Highlights

  • Standardized Exception Handling Framework: Introduced a comprehensive exception handling framework, documented in a new Architectural Decision Record (ADR-001), to standardize error codes, improve diagnostics, and enhance API response formatting across ArcadeDB.
  • Enhanced ArcadeDBException: The base ArcadeDBException class has been refactored to be abstract, incorporating standardized error codes, a diagnostic context map, JSON serialization capabilities, HTTP status code mapping, and timestamp tracking. Legacy constructors are retained but marked as deprecated for backward compatibility.
  • New ErrorCode Enum: A new ErrorCode enum has been added, providing a categorized and numeric system for error identification across various domains such as Database, Transaction, Query, Security, Storage, and Network. Each code includes a default message and category.
  • Specialized Exception Classes: New specific exception classes like DatabaseException, QueryException, SecurityException, StorageException, NetworkException, and InternalException have been introduced, extending the enhanced ArcadeDBException to provide more granular error handling and specific HTTP status mappings.
  • ExceptionBuilder Utility: A fluent ExceptionBuilder utility has been implemented to provide an ergonomic way to construct exceptions with error codes, custom messages, causes, and diagnostic context, promoting consistent exception creation.
  • Migration to InternalException: Existing usages of ArcadeDBException for general internal errors in utility and parser files have been replaced with the newly introduced InternalException, aligning with the new structured error handling approach.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@mergify
Copy link
Contributor

mergify bot commented Dec 17, 2025

🧪 CI Insights

Here's what we observed from your CI run for 1d8d116.

🟢 All jobs passed!

But CI Insights is watching 👀

Copy link
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 does an excellent job of introducing a standardized and robust exception handling framework. The new ArcadeDBException hierarchy, ErrorCode enum, and ExceptionBuilder provide a solid foundation for consistent error handling, improved diagnostics, and better API responses. The changes are well-designed and the phased migration plan is thoughtful. My review includes suggestions to further improve consistency, performance, and API design within the new framework. These include optimizing an enum lookup, ensuring consistent map implementations, and refining the API of the new exception classes to prevent misuse. Overall, this is a high-quality contribution that significantly improves the project's maintainability.

@robfrank
Copy link
Collaborator Author

Code Review Comments - All Addressed ✅

I've reviewed and addressed all 6 code review comments from the Copilot reviewer:

1. ADR Exception Code Table - FIXED

✅ Expanded the error code ranges table in ADR-001-exception-handling.md to include all 11 categories:

  • Added Graph (9000-9999)
  • Added Import/Export (10000-10999)
  • Added Internal (99000-99999)

The table now comprehensively documents all error code ranges with examples.

2. ArcadeDBException.toString() - FIXED

✅ Refactored context string building to use Stream API with Collectors.joining:

if (!context.isEmpty()) {
  sb.append(" {")
    .append(context.entrySet().stream()
      .map(entry -> entry.getKey() + "=" + entry.getValue())
      .collect(Collectors.joining(", ")))
    .append("}");
}

3. ErrorCode.fromCode() Performance - FIXED

✅ Optimized from O(N) to O(1) using a static unmodifiable map:

private static final Map<Integer, ErrorCode> CODE_MAP =
    java.util.stream.Stream.of(values())
        .collect(Collectors.toUnmodifiableMap(ErrorCode::getCode, e -> e));

public static ErrorCode fromCode(final int code) {
  return CODE_MAP.getOrDefault(code, INTERNAL_ERROR);
}

4. ExceptionBuilder Context Map - FIXED

✅ Changed from HashMap to LinkedHashMap for consistent insertion-order preservation:

private final Map<String, Object> context = new LinkedHashMap<>();

5. ExceptionBuilder Exception Handling - FIXED

✅ Changed from throwing generic RuntimeException to standardized InternalException:

throw new InternalException("Failed to build exception: " + exceptionClass.getName(), e);

6. InternalException API - FIXED

✅ Made ErrorCode-accepting constructors protected to prevent misuse:

protected InternalException(final ErrorCode errorCode, final String message) {
  super(errorCode, message);
}

This enforces proper use of specific exception types while keeping the string-based public constructors available.

Build Status

✅ Engine module compiles successfully with all improvements
✅ All changes maintain backward compatibility
✅ No performance regressions introduced

Copy link
Collaborator Author

@robfrank robfrank left a comment

Choose a reason for hiding this comment

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

All code review suggestions have been implemented and verified. The changes improve code quality through better performance, readability, and API design consistency.

| Index | 8000-8999 | Index operations | 8001: INDEX_NOT_FOUND, 8002: DUPLICATE_KEY |

### Enhanced ArcadeDBException Design

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

FIXED - Expanded the error code ranges table to include all 11 categories:

  • Added Graph (9000-9999)
  • Added Import/Export (10000-10999)
  • Added Internal (99000-99999)

The table now comprehensively shows all error code ranges and their respective examples for clarity and consistency.

private ErrorCode errorCode;
private String message;
private Throwable cause;
private final Map<String, Object> context = new HashMap<>();
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

FIXED - Changed context map to use LinkedHashMap for consistent insertion-order preservation, matching the behavior in ArcadeDBException.

@robfrank robfrank force-pushed the feat/2866-exceptions branch from fc02cd0 to 786b40d Compare December 17, 2025 23:17
@codacy-production
Copy link

codacy-production bot commented Dec 17, 2025

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
-0.01% 25.54%
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (f7a27da) 77229 49479 64.07%
Head commit (1d8d116) 77489 (+260) 49637 (+158) 64.06% (-0.01%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#3048) 278 71 25.54%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

See your quality gate settings    Change summary preferences

@robfrank robfrank requested a review from lvca December 18, 2025 07:56
@robfrank robfrank added the enhancement New feature or request label Dec 18, 2025
@robfrank robfrank added this to the 25.12.1 milestone Dec 18, 2025
@robfrank robfrank changed the title feat: replace ArcadeDBException with InternalException for better err… TASK-P1-004: Design Exception Hierarchy Dec 18, 2025
@robfrank robfrank force-pushed the feat/2866-exceptions branch 3 times, most recently from 3aee0af to cee01b9 Compare December 20, 2025 10:58
Copy link
Contributor

@lvca lvca left a comment

Choose a reason for hiding this comment

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

I don't like to mix the http code concept all over the modules, I think it's a violation of responsibility. We could just have a HttpCodeResolver that takes an exception and returns the http code if this is the requirement.

* @return the HTTP status code
*/
@Override
public int getHttpStatus() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Not nice the basic exception has concepts of http here


// ========== Network Errors (6xxx) ==========
/** Failed to establish or maintain connection */
CONNECTION_ERROR(6001, "Connection error"),
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here, the engine base model now has concepts from other modules (network)

* @return the HTTP status code
*/
@Override
public int getHttpStatus() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of contaminating all the exceptions with HTTP concept and codes, I'd prefer to have 1 method that returns the Http code from any exception, and it should be in the http server.

@robfrank robfrank force-pushed the feat/2866-exceptions branch from cee01b9 to 1d8d116 Compare December 22, 2025 15:50
@robfrank robfrank modified the milestones: 25.12.1, 26.1.1 Jan 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TASK-P1-004: Design Exception Hierarchy

3 participants