Skip to content
This repository has been archived by the owner on Jan 2, 2021. It is now read-only.

Collect CPP error logs into diagnostics. #296

Merged
merged 6 commits into from
Jan 6, 2020
Merged

Conversation

jinwoo
Copy link
Contributor

@jinwoo jinwoo commented Dec 30, 2019

@jinwoo
Copy link
Contributor Author

jinwoo commented Dec 30, 2019

The source location of the CPP error from CI is different from what I see locally. It is (2, 1) locally but (2, -1) in CI. I'll change the column number to -1 but I'm worried that it'd make cppTests fail locally.

$ liftIO
$ (Right <$> (runCpp dflags {log_action = logAction cppLogs} filename
$ if isOnDisk then Nothing else Just contents))
`catch` (\(e :: SomeException) -> do
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don’t catch SomeException. We use async exceptions very heavily to kill the currently running computation and code that catches SomeException will also catch ThreadKilled.
We already depend on safe-exceptions so catchIO might be a reasonable option or if this really does throw exceptions other than IOException, catch from Control.Exception.Safe will not catch async exceptions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I traced the code and figured that the exceptions thrown from runCpp are GhcException. Updated. And now using catch and throw from safe-exception.

test/exe/Main.hs Outdated
T.unlines
[ " error: unterminated #ifdef",
" #ifdef FOO",
" ^"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My CPP doesn’t seem to have the carret in the output here so it would probably be good to make this test a bit more fuzzy and only assert on error: unterminated #ifdef which is hopefully present in the output of most if not all CPP implementations.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reduced to error: unterminated because the error message on my mac is error: unterminated conditional directive.

test/exe/Main.hs Outdated
expectDiagnostics
[ ( "Testing.hs",
[ ( DsError,
(2, -1),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get the same line numbers as CI but a different failure as mentioned below. My guess is that this is because we’re using different CPP implementations (I’m using whatever the default is on linux when invoked via stack, I guess you might be on Windows or MacOS). I would like to avoid this test being flaky locally so maybe we can just test against both (2,-1) and (2,0) (by catching HUnitFailure on the first try) and succeed if either of them succeeds?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I'm doing this on my mac at the moment. What about this?

@jinwoo jinwoo requested a review from cocreature January 3, 2020 19:25
Copy link
Collaborator

@cocreature cocreature left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thanks for addressing my comments!

@cocreature cocreature merged commit 8f50699 into haskell:master Jan 6, 2020
@jinwoo jinwoo deleted the cpp branch January 7, 2020 12:43
pepeiborra pushed a commit to pepeiborra/ghcide that referenced this pull request Feb 1, 2020
pepeiborra pushed a commit to pepeiborra/ide that referenced this pull request Dec 29, 2020
pepeiborra pushed a commit to pepeiborra/ide that referenced this pull request Dec 29, 2020
pepeiborra pushed a commit to pepeiborra/ide that referenced this pull request Dec 29, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CPP error messages are terrible
2 participants