Skip to content
This repository has been archived by the owner on Jun 1, 2023. It is now read-only.

Log warning message when failing to generate graph #100

Merged
merged 3 commits into from
May 11, 2020
Merged

Conversation

mattt
Copy link
Contributor

@mattt mattt commented May 6, 2020

Resolves #48

As of #52, we log any errors caught during graph generation:

2020-05-06T12:00:00-0700 error: Error Domain=NSPOSIXErrorDomain Code=13 "Permission denied"

Although this involves error handling, the error log level is inappropriate here, because the failure isn't critical. Documentation may be generated even if GraphViz graphs aren't available.

This PR changes the log level to warning and wraps the raw NSError with some more actionable information:

2020-05-06T12:00:00-0700 warning: Failed to generate relationship graph for _____________. Please ensure that GraphViz binaries are accessible from your PATH. (Error Domain=NSPOSIXErrorDomain Code=13 "Permission denied")

I was able to reproduce #52 locally by running brew unlink graphviz. Since the formula for swift-doc now includes GraphViz as an (optional) dependency, this is much less likely to occur going forward.

@mattt mattt requested a review from kaishin May 6, 2020 19:47
@mattt mattt added the enhancement New feature or request label May 6, 2020
Copy link
Contributor

@kaishin kaishin left a comment

Choose a reason for hiding this comment

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

Works as advertised 😉

PS: Not tied to this PR but I think emphasizing that GraphViz is a peer dependency would prevent users from getting confused by this error message. Doesn't make for a good experience to see this error on first run. Either that or skipping this code branch when not running the diagram subcommand.

@mattt
Copy link
Contributor Author

mattt commented May 7, 2020

Thanks for reviewing this, @kaishin!

PS: Not tied to this PR but I think emphasizing that GraphViz is a peer dependency would prevent users from getting confused by this error message. Doesn't make for a good experience to see this error on first run. Either that or skipping this code branch when not running the diagram subcommand.

I agree that this is an important detail to get right. Do you have a specific idea for where we can / should communicate swift-doc's relationship to the GraphViz binaries?

To clarify: The GraphViz binary is only used to generate SVG diagrams in the HTML output of the generate subcommand. The diagram subcommand imports the GraphViz Swift module dependency, but doesn't actually require any binaries to generate the DOT language output. (You can do brew unlink graphviz and then swift doc diagram without any errors).

@kaishin
Copy link
Contributor

kaishin commented May 8, 2020

Thanks for the clarification!

Do you have a specific idea for where we can / should communicate swift-doc's relationship to the GraphViz binaries?

The first idea I got was to have a "Peer Dependencies" subsection in the readme. If that's too much then a note right below where it's first mentioned could do the job.

A better way would be to let the user know whenever they run the generate subcommand, but I am not sure how bullet-proof checking for the executable can be.

@mattt
Copy link
Contributor Author

mattt commented May 8, 2020

The first idea I got was to have a "Peer Dependencies" subsection in the readme. If that's too much then a note right below where it's first mentioned could do the job.

I'm not as familiar with the term "peer dependency". Based on this write-up, I don't think this is quite the right term. But! It would be a great way to describe any generator plugin system we might add in the future.

For now, I added GraphViz as an "(optional) requirement" (oxymoronic though that may be) with da2cd6c. That seemed like a reasonable first step.

A better way would be to let the user know whenever they run the generate subcommand, but I am not sure how bullet-proof checking for the executable can be.

I think warning on failure is a reasonable solution. It has the advantages of not making extra work and not having the potential for false positive or negative results. Like with validating email addresses, the only real way to see if an email is valid is to send a message and see if they get it.

@kaishin
Copy link
Contributor

kaishin commented May 9, 2020

I agree that the term “peer dependency” isn’t quite right here. I also thought of “soft” and “indirect”.

At any rate, what you proposed is probably enough for now. If it isn’t if won’t be the last time this comes up 😉

@mattt mattt merged commit bedc0b3 into master May 11, 2020
@mattt mattt deleted the handle-posix-errors branch May 11, 2020 17:30
@mattt
Copy link
Contributor Author

mattt commented May 11, 2020

At any rate, what you proposed is probably enough for now. If it isn’t if won’t be the last time this comes up 😉

@kaishin Indeed. Thanks for sharing your thoughts about this. All really valuable groundwork as we continue to negotiate and evolve how all the different pieces fit together here.

mattt added a commit that referenced this pull request May 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"Permission denied" error, documentation is still generated
2 participants