Class RichErrorMessages

java.lang.Object
org.ek9lang.compiler.common.RichErrorMessages

public final class RichErrorMessages extends Object
Provides rich error messages for AI-assisted development. These detailed messages are appended to error output when error level E3 is enabled, helping AI assistants understand and resolve EK9 compilation errors more effectively.

This class is a pure lookup - it contains no state. The decision of whether to based on the per-compilation error level from CompilerFlags.

Messages are loaded from individual .txt resource files in richErrorMessages/, listed by richErrorMessages/rich-error-manifest.txt. This allows researchers to create alternative message packs without modifying Java code.

Each error code has a rich message containing:

  • DIAGNOSIS - what went wrong
  • ACTION - steps to resolve
  • SEE ALSO - related errors and docs
  • Method Details

    • loadMessagePack

      public static void loadMessagePack(Path zipPath)
      Load alternative rich error messages from a message pack zip file. Messages in the pack override built-in messages; codes not in the pack fall back to the built-in defaults.
      Parameters:
      zipPath - path to the message pack zip file
    • getRichMessage

      public static String getRichMessage(String errorCode)
      Get the rich message for an error code. Checks the override pack first, then falls back to built-in messages.
      Parameters:
      errorCode - The error code (e.g., "E50001")
      Returns:
      The rich message, or null if not found
    • getRichMessageWithExample

      public static String getRichMessageWithExample(String errorCode)
      The rich message for an error code followed by its [EXAMPLE] section: the error catalogue's compiled failing source and its compiled fixes (ErrorExamples.exampleSection(String)), as plain text. This is what ek9 -h <CODE> and -E3 show; a code the catalogue holds nothing for shows its message unchanged. The example is never part of a message pack - a pack replaces the prose, the catalogue is the code.
      Parameters:
      errorCode - The error code (e.g., "E07235")
      Returns:
      The rich message with its example section, or null if there is no rich message
    • resetOverrides

      public static void resetOverrides()
      Reset overrides back to empty (for testing).