Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/CLI/Runners.hs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ runMatch OptsMatch{..} = do
condition <- traverse parseConditionThrows _when
substs <- matchProgramWithRule prog (rule ptn condition) (RuleContext buildTerm)
if null substs
then logDebug "Provided pattern was not matched, no substitutions are built"
then throwIO EmptySubstsOnMatch
else putStrLn (P.printSubsts' substs (_sugarType, UNICODE, _flat, defaultMargin))
where
rule :: Expression -> Maybe Y.Condition -> Y.Rule
Expand Down
2 changes: 2 additions & 0 deletions src/CLI/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,15 @@ data CmdException
| CouldNotReadFromStdin String
| CouldNotDataize
| CouldNotPrintExpressionInXMIR
| EmptySubstsOnMatch
deriving (Exception)

instance Show CmdException where
show (InvalidCLIArguments msg) = printf "Invalid set of arguments: %s" msg
show (CouldNotReadFromStdin msg) = printf "Could not read input from stdin\nReason: %s" msg
show CouldNotDataize = "Could not dataize given program"
show CouldNotPrintExpressionInXMIR = "Could not print expression with --output=xmir, only program printing is allowed"
show EmptySubstsOnMatch = "Provided pattern was not matched, no substitutions are built"

data Command
= CmdRewrite OptsRewrite
Expand Down
6 changes: 6 additions & 0 deletions test/CLISpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1027,3 +1027,9 @@ spec = do
testCLIFailed
["match", "--pattern=[[!B]]", "--when=hello"]
["[ERROR]: Couldn't parse given condition"]

it "fails on empty substitutions" $
withStdin "{Q.x.y}" $
testCLIFailed
["match", "--pattern=$.!a"]
["[ERROR]"]
Loading