Comprehensive error reporting system with source positions, suggestions, and multiple output formats including JSON for tooling integration.
Main error representation with source positions and contextual information.
-- | Multiple compilation errors
newtype MultipleErrors = MultipleErrors { runMultipleErrors :: [ErrorMessage] }
-- | Individual error message
data ErrorMessage = ErrorMessage [ErrorMessageHint] SimpleErrorMessage
-- | Simple error message content
data SimpleErrorMessage
= ErrorParsingModule ParseError
| ErrorParsingFFIModule FilePath
| ModuleNotFound ModuleName
| FileIOError String IOError
| InfiniteType SourceType
| InfiniteKind SourceKind
| MultipleValueDeclarations Ident
| DuplicateModule ModuleName
| CycleInDeclaration Ident
| CycleInModules [ModuleName]
| NameIsUndefined Ident
| UndefinedTypeVariable (ProperName 'TypeName)
| PartiallyAppliedSynonym (Qualified (ProperName 'TypeName))
| EscapedSkolem Text Int SourceType
| TypesDoNotUnify SourceType SourceType
| KindsDoNotUnify SourceKind SourceKind
| ConstrainedTypeUnified SourceType SourceConstraint
| OverlappingInstances (Qualified (ProperName 'ClassName)) [SourceType] [Qualified Ident]
| NoInstanceFound SourceConstraint
| DuplicateLabel Label (Maybe Expr)
| DuplicateValueDeclaration Ident
| ArgListLengthsDiffer Ident
| OverlappingArgNames (Maybe Ident)
| MissingClassMember Ident
| ExtraneousClassMember Ident (Qualified (ProperName 'ClassName))
| ExpectedType SourceKind SourceType
| IncorrectConstructorArity (Qualified (ProperName 'ConstructorName))
| ExprDoesNotHaveType Expr SourceType
| PropertyIsMissing Label
| AdditionalProperty Label
| OrphanInstance Ident (Qualified (ProperName 'ClassName)) [SourceType]
| InvalidNewtype (ProperName 'TypeName)
| InvalidInstanceHead SourceType
| TransitiveExportError DeclarationRef [DeclarationRef]
| ShadowedName Ident
| ShadowedTypeVar Text
| UnusedImport ModuleName
| UnusedExplicitImport ModuleName [Ident] (Maybe ModuleName) [DeclarationRef]
| UnusedDctorImport ModuleName (ProperName 'TypeName) [ProperName 'ConstructorName]
| UnusedDctorExplicitImport ModuleName (ProperName 'TypeName) [ProperName 'ConstructorName] [ProperName 'ConstructorName]
| ImplicitQualifiedImport ModuleName (Maybe ModuleName) [DeclarationRef]
| ImplicitImport ModuleName [DeclarationRef]
| HidingImport ModuleName [DeclarationRef]
| CaseBinderLengthDiffer Int Int
| IncorrectAnonymousArgument
| InvalidOperatorInBinder (Qualified (OpName 'ValueOpName))
| CannotGeneralizeRecursiveFunction Ident SourceType
| CannotDeriveNewtypeForData (ProperName 'TypeName)
| ExpectedWildcard (ProperName 'TypeName)
| CannotUseBindWithDo (ProperName 'ModuleName)
| ClassOperator (Qualified (ProperName 'ClassName)) (OpName 'ValueOpName)
| MisleadingEmptyTypeImport ModuleName (ProperName 'TypeName)
| ImportHidingModule ModuleName
| WildcardNotInType
| MissingTypeDeclaration Ident SourceType
| MissingKindDeclaration KindSignatureFor (ProperName 'TypeName) SourceKind
| OverlappingPattern [[Binder]] Bool
| IncompleteExhaustivityCheck
-- ... more error typesContextual hints and suggestions for better error reporting.
-- | Error message hints
data ErrorMessageHint
= ErrorUnifyingTypes SourceType SourceType
| ErrorInExpression Expr
| ErrorInModule ModuleName
| ErrorInInstance (Qualified (ProperName 'ClassName)) [SourceType]
| ErrorInSubsumption SourceType SourceType
| ErrorCheckingAccessor Expr PSString
| ErrorCheckingType Expr SourceType
| ErrorCheckingKind SourceType SourceKind
| ErrorInferringType Expr
| ErrorInApplication Expr SourceType Expr
| ErrorInDataConstructor (ProperName 'ConstructorName)
| ErrorInTypeConstructor (ProperName 'TypeName)
| ErrorInBindingGroup (NonEmpty Ident)
| ErrorInDataBindingGroup [ProperName 'TypeName]
| ErrorInTypeSynonym (ProperName 'TypeName)
| ErrorInValueDeclaration Ident
| ErrorInTypeDeclaration Ident
| ErrorInTypeClassDeclaration (ProperName 'ClassName)
| ErrorInKindDeclaration (ProperName 'TypeName)
| ErrorInRoleDeclaration (ProperName 'TypeName)
| ErrorInForeignImport Ident
| ErrorSolvingConstraint SourceConstraint
| PositionedError SourceSpanHuman-readable error formatting with colors and suggestions.
-- | Pretty print multiple errors
prettyPrintMultipleErrors :: PPEOptions -> MultipleErrors -> Text
-- | Pretty print single error
prettyPrintSingleError :: PPEOptions -> ErrorMessage -> Text
-- | Pretty print options
data PPEOptions = PPEOptions
{ ppeCodeColor :: Maybe AnsiColor -- Syntax highlighting
, ppeFull :: Bool -- Show full context
, ppeLevel :: PPELevel -- Verbosity level
, ppeShowSourceSpans :: Bool -- Show source positions
, ppeCodeContext :: Int -- Lines of code context
}
-- | Pretty print verbosity levels
data PPELevel = PPELevel1 | PPELevel2 | PPELevel3
-- | Default pretty print options
defaultPPEOptions :: PPEOptions
-- | ANSI color codes
data AnsiColor = Red | Green | Yellow | Blue | Magenta | Cyan | White | BlackBox-based error formatting for structured output.
-- | Pretty print errors using boxes
prettyPrintMultipleErrorsBox :: Bool -> MultipleErrors -> Box.Box
-- | Error box formatting
errorMessageBox :: Bool -> ErrorMessage -> Box.Box
-- | Source span box formatting
sourceSpanBox :: SourceSpan -> Box.Box
-- | Code context box
codeContextBox :: FilePath -> SourceSpan -> Box.Box
-- | Box utilities
indent :: Int -> Box.Box -> Box.Box
colorBox :: AnsiColor -> Box.Box -> Box.BoxJSON serialization for tooling integration and IDE support.
-- | Convert errors to JSON
multipleErrorsToJson :: MultipleErrors -> Value
-- | JSON error format
data JSONError = JSONError
{ jsonErrorMessage :: Text
, jsonErrorHints :: [Text]
, jsonErrorFilename :: Maybe FilePath
, jsonErrorPosition :: Maybe SourcePos
, jsonErrorSuggestion :: Maybe Suggestion
, jsonErrorErrorCode :: Text
}
-- | Error suggestions
data Suggestion = Suggestion
{ suggestionText :: Text
, suggestionReplacement :: Maybe Text
, suggestionNote :: Maybe Text
}
-- | Convert to JSON error format
errorMessageToJSON :: ErrorMessage -> JSONError
-- | Parse JSON errors
parseJSONErrors :: Value -> Either String MultipleErrorsUnique error codes for programmatic error handling.
-- | Get error code for message
errorCode :: ErrorMessage -> Text
-- | All available error codes
allErrorCodes :: [Text]
-- | Error code categories
data ErrorCategory
= ParseError_ -- Parsing errors
| TypeCheckError -- Type checking errors
| KindCheckError -- Kind checking errors
| ScopeError -- Scoping and name resolution
| ImportError -- Import/export errors
| InstanceError -- Type class instance errors
| DerivingError -- Deriving errors
| FFIError -- Foreign function interface
| LintError -- Linting warnings
-- | Categorize error by code
categorizeError :: Text -> ErrorCategory
-- | Check if error code is warning
isWarning :: Text -> BoolFilter and suppress specific error types and codes.
-- | Filter errors by codes
filterErrors :: [Text] -> MultipleErrors -> MultipleErrors
-- | Filter warnings
filterWarnings :: MultipleErrors -> MultipleErrors
-- | Filter by error category
filterByCategory :: ErrorCategory -> MultipleErrors -> MultipleErrors
-- | Suppress specific error types
suppressErrors :: [SimpleErrorMessage -> Bool] -> MultipleErrors -> MultipleErrors
-- | Convert warnings to errors (strict mode)
warningsToErrors :: MultipleErrors -> MultipleErrorsSource position tracking and error location reporting.
-- | Add source position to error
addHint :: ErrorMessageHint -> ErrorMessage -> ErrorMessage
-- | Position error at source span
positionError :: SourceSpan -> ErrorMessage -> ErrorMessage
-- | Add source context to error
addSourceContext :: FilePath -> ErrorMessage -> IO ErrorMessage
-- | Extract source span from error
getErrorSpan :: ErrorMessage -> Maybe SourceSpan
-- | Sort errors by position
sortErrorsByPosition :: MultipleErrors -> MultipleErrorsError context tracking through compilation phases.
-- | Error context monad
type ErrorContext = ReaderT [ErrorMessageHint] (Either MultipleErrors)
-- | Run with error context
runErrorContext :: ErrorContext a -> Either MultipleErrors a
-- | Add context hint
withContext :: ErrorMessageHint -> ErrorContext a -> ErrorContext a
-- | Collect multiple errors
collectErrors :: [ErrorContext ()] -> ErrorContext ()
-- | Convert single error to multiple
singleError :: ErrorMessage -> MultipleErrors
-- | Combine multiple error collections
combineErrors :: [MultipleErrors] -> MultipleErrorsWarning generation and management system.
-- | Warning types
data Warning
= UnusedImportWarning ModuleName DeclarationRef
| UnusedLocalBindingWarning Ident
| ShadowedNameWarning Ident
| MissingTypeSignatureWarning Ident
| RedundantConstraintWarning SourceConstraint
| DeprecationWarning Text
| ImplicitImportWarning ModuleName [DeclarationRef]
-- | Convert warning to error message
warningToError :: Warning -> ErrorMessage
-- | Collect warnings during compilation
collectWarnings :: [Warning] -> MultipleErrors
-- | Warning severity levels
data WarningSeverity = Info | Warning | Error
-- | Set warning severity
setWarningSeverity :: Warning -> WarningSeverity -> WarningRich diagnostic information for IDE integration.
-- | Diagnostic information
data Diagnostic = Diagnostic
{ diagRange :: SourceSpan
, diagSeverity :: DiagnosticSeverity
, diagCode :: Maybe Text
, diagSource :: Text
, diagMessage :: Text
, diagRelatedInformation :: [DiagnosticRelatedInformation]
}
-- | Diagnostic severity (LSP compatible)
data DiagnosticSeverity = DiagError | DiagWarning | DiagInfo | DiagHint
-- | Related diagnostic information
data DiagnosticRelatedInformation = DiagnosticRelatedInformation
{ driLocation :: SourceSpan
, driMessage :: Text
}
-- | Convert error to diagnostic
errorToDiagnostic :: ErrorMessage -> Diagnostic
-- | Generate diagnostics for file
generateDiagnostics :: FilePath -> MultipleErrors -> [Diagnostic]-- | Error construction helpers
mkSimpleError :: SimpleErrorMessage -> ErrorMessage
mkErrorWithHints :: [ErrorMessageHint] -> SimpleErrorMessage -> ErrorMessage
-- | Common error patterns
typeError :: SourceType -> SourceType -> ErrorMessage
kindError :: SourceKind -> SourceKind -> ErrorMessage
scopeError :: Ident -> ErrorMessage
parseError :: ParseError -> ErrorMessage
-- | Error combinators
addHints :: [ErrorMessageHint] -> ErrorMessage -> ErrorMessage
modifyError :: (SimpleErrorMessage -> SimpleErrorMessage) -> ErrorMessage -> ErrorMessage-- | Error accumulation monad
type ErrorAccum = Writer MultipleErrors
-- | Accumulate error
tellError :: ErrorMessage -> ErrorAccum ()
-- | Accumulate multiple errors
tellErrors :: MultipleErrors -> ErrorAccum ()
-- | Run error accumulation
runErrorAccum :: ErrorAccum a -> (a, MultipleErrors)
-- | Error-or-value result
type ErrorOr a = Either MultipleErrors a
-- | Lift to error-or
liftError :: ErrorMessage -> ErrorOr a
liftErrors :: MultipleErrors -> ErrorOr a-- | Error recovery strategies
data RecoveryStrategy
= SkipDeclaration -- Skip malformed declaration
| DefaultValue SourceType -- Use default value for type
| ContinueWithWarning -- Continue with warning
| AbortCompilation -- Stop compilation
-- | Apply recovery strategy
applyRecovery :: RecoveryStrategy -> ErrorMessage -> Either ErrorMessage a
-- | Recoverable error
data RecoverableError = RecoverableError
{ reError :: ErrorMessage
, reRecovery :: Maybe RecoveryStrategy
}
-- | Convert to recoverable error
makeRecoverable :: RecoveryStrategy -> ErrorMessage -> RecoverableError