From 4d56a673346e5e5bde0de0744a6c794537c27172 Mon Sep 17 00:00:00 2001 From: Nikolai Ponomarev Date: Sat, 26 Oct 2024 11:50:55 +0300 Subject: [PATCH] Make error messages more clear --- lamagraph-compiler/lamagraph-compiler.cabal | 3 +++ lamagraph-compiler/package.yaml | 1 + lamagraph-compiler/src/Lamagraph/Compiler/PrettyLml.hs | 8 ++++++-- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lamagraph-compiler/lamagraph-compiler.cabal b/lamagraph-compiler/lamagraph-compiler.cabal index ce8fb45..79553af 100644 --- a/lamagraph-compiler/lamagraph-compiler.cabal +++ b/lamagraph-compiler/lamagraph-compiler.cabal @@ -61,6 +61,7 @@ library , lens , prettyprinter , relude + , string-interpolate default-language: GHC2021 executable lamagraph-compiler-exe @@ -84,6 +85,7 @@ executable lamagraph-compiler-exe , lens , prettyprinter , relude + , string-interpolate default-language: GHC2021 test-suite lamagraph-compiler-test @@ -115,6 +117,7 @@ test-suite lamagraph-compiler-test , lens , prettyprinter , relude + , string-interpolate , tasty , tasty-golden , tasty-hedgehog diff --git a/lamagraph-compiler/package.yaml b/lamagraph-compiler/package.yaml index 16486f8..bfda82f 100644 --- a/lamagraph-compiler/package.yaml +++ b/lamagraph-compiler/package.yaml @@ -26,6 +26,7 @@ dependencies: - extra - lens - prettyprinter + - string-interpolate language: GHC2021 diff --git a/lamagraph-compiler/src/Lamagraph/Compiler/PrettyLml.hs b/lamagraph-compiler/src/Lamagraph/Compiler/PrettyLml.hs index 74aabda..9e27ea0 100644 --- a/lamagraph-compiler/src/Lamagraph/Compiler/PrettyLml.hs +++ b/lamagraph-compiler/src/Lamagraph/Compiler/PrettyLml.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE QuasiQuotes #-} {-# OPTIONS_GHC -Wno-orphans #-} {- | Orphan instances for pretty-printing LamagraphML @@ -8,6 +9,7 @@ module Lamagraph.Compiler.PrettyLml () where import Relude +import Data.String.Interpolate (i) import Data.Text qualified as T import Prettyprinter @@ -17,7 +19,9 @@ import Lamagraph.Compiler.Syntax prettyADTVar :: LLmlType (LmlcPass pass) -> Doc ann prettyADTVar (L _ (LmlTyVar _ varName)) = "'" <> pretty varName -prettyADTVar _ = error "Internal pretty-printer error: cannot have complex types in type parameters" +prettyADTVar t = + error + [i|Internal pretty-printer error: expected list of type variables in AST as a type parameters, but got #{pretty t}|] prettyADTVars :: [LLmlType (LmlcPass pass)] -> Doc ann prettyADTVars [] = emptyDoc @@ -31,7 +35,7 @@ prettyChar '\'' = "\\\'" prettyChar '\n' = "\\\n" prettyChar c | c `elem` ['\32' .. '\127'] = pretty c - | otherwise = error "Internal pretty-printer error: trying to print unsupported character" + | otherwise = error [i|Internal pretty-printer error: trying to print unsupported in LML character "#{c}"|] prettyString :: Text -> Doc ann prettyString str = mconcat $ map prettyChar (toString str)