imp: improve bad regexp error message

Eg '(?:foo)' is not malformed, it's just not supported.
https://hledger.org/hledger.html#hledgers-regular-expressions
This commit is contained in:
Simon Michael 2024-07-24 11:06:13 +01:00
parent fa8d223858
commit d19b353bfb
5 changed files with 5 additions and 5 deletions

View File

@ -817,7 +817,7 @@ makeHledgerClassyLenses ''ReportSpec
-- >>> _rsQuery <$> setEither querystring ["assets"] defreportspec
-- Right (Acct (RegexpCI "assets"))
-- >>> _rsQuery <$> setEither querystring ["(assets"] defreportspec
-- Left "This regular expression is malformed, please correct it:\n(assets"
-- Left "This regular expression is invalid or unsupported, please correct it:\n(assets"
-- >>> _rsQuery $ set querystring ["assets"] defreportspec
-- Acct (RegexpCI "assets")
-- >>> _rsQuery $ set querystring ["(assets"] defreportspec

View File

@ -136,7 +136,7 @@ toRegexCI = memo $ \s -> mkRegexErr s (RegexpCI s <$> makeRegexOptsM defaultComp
-- | Make a nice error message for a regexp error.
mkRegexErr :: Text -> Maybe a -> Either RegexError a
mkRegexErr s = maybe (Left errmsg) Right
where errmsg = T.unpack $ "This regular expression is malformed, please correct it:\n" <> s
where errmsg = T.unpack $ "This regular expression is invalid or unsupported, please correct it:\n" <> s
-- Convert a Regexp string to a compiled Regex, throw an error
toRegex' :: Text -> Regexp

View File

@ -268,7 +268,7 @@ hledger: Error: /Users/simon/src/hledger/hledger/test/errors/./parseable-regexps
3 | alias /(/ = a
| ^
This regular expression is malformed, please correct it:
This regular expression is invalid or unsupported, please correct it:
(
```

View File

@ -4,7 +4,7 @@ $$$ hledger check -f parseable-regexps.j
3 \| alias \/\(\/ = a
\| \^
This regular expression is malformed, please correct it:
This regular expression is invalid or unsupported, please correct it:
\(
/

View File

@ -130,7 +130,7 @@ $ hledger -f - print expr:"not tag:transactiontag=B"
# ** 9. Having parentheses directly follow 'not' sees 'not' as part of a query.
$ hledger -f - print expr:"not(tag:transactiontag=B)"
>2
hledger: Error: This regular expression is malformed, please correct it:
hledger: Error: This regular expression is invalid or unsupported, please correct it:
not(tag:transactiontag=B
>=1