-
Notifications
You must be signed in to change notification settings - Fork 424
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Gracefully handle output of bitstring :message
in %Credo.Issue{}
#1120
Comments
Hi, yes, we should definitely do something about this 👍 What do you think about putting a simple Line 728 in 3fb97c5
We did something similar to |
Indeed, I ended up with this below, which certainly produces strings that credo can successfully work with. But reading it now with fresh eyes, I don't like how it is transforming the input in the case where
|
Mmh, I get the feeling that we are not yet finished analysing the problem (the StackOverflow post that this snippet seems to be copied from also left me no wiser) ... Quick thoughts:
Let me know your thoughts. |
This replaces every invalid character with the same mark, "�" by default. So the valid surrounding characters will offer the user context to help. As a user, I'd rather receive 90% of a credo message with an invalid character than 0%.
Here is the test case I've been working on in
|
In my mind, we should not assume too much about the data we're given (especially when reading the source code of And: We can not use Checking and warning with Your example shows that even the |
Cool. How about something like this? I tried to keep Credo's helpful conversational style, but I admit to a tendency to over-word things. I do think it's nice when a message, when searched, yields exactly the right results, so I considered that in this proposed wording.
|
Why would we overwrite a message instead of just printing a warning?
What does this even mean? What "right results"? |
Yes, of course. Definitely better. I outline a few approaches below.
Accurate search hits with minimum false positives. Users naturally search for the warning phrase verbatim. Approach 1. Skip Malformed Issues and/or Malformed MessagesWe could, for default output, skip malformed issues here, either by skipping the issue entirely or by skipping the invalid message, leaving the other issue elements to be output:
But then that leaves the question of what to do about the other outputs: flycheck, json, oneline, and sarif. Approach 2. Filter Out Malformed Issues from ExecutionAlternatively, we could filter out issues with invalid messages from Line 514 in 3fb97c5
But this seems strange to filter out issues at this level of abstraction due to an output concern. And lots of other code calls this function. Approach 3. Smallest change and most simpleSince credo/lib/credo/cli/output/ui.ex Line 57 in 3fb97c5
This is the smallest surface area solution, with only two direct callers. RegardlessTo help plugin authors, I think regardless of which approach we take, we would add checks for invalid message and trigger values here: Lines 183 to 204 in 3fb97c5
|
Thx for reporting this! 👍 It should be be fixed in the latest version of Credo. If it is not, please feel free to re-open this issue! |
To make it easier for credo plugin authors, should credo handle the cases where
:message
or:trigger
values end up as bitstrings? Credo could always convert these values to strings before rendering its output. And that way, we would have it happening in one place for every plugin instead of each plugin potentially gradually discovering the need.The Story
A particular credo plugin was inadvertently bubbling up bitstrings in its
%Credo.Issue{}
structs in the:message
and:trigger
fields. It only did this in the presence of UTF-8 non-ASCII characters.Credo does not expect these bitstrings, and runs into trouble somewhere in its line-wrapping logic. We end up with something like this upon running
mix credo
:I've offered a PR to that plugin to ensure that it always converts
:message
and:trigger
to string values.But maybe it's better for the whole credo ecosystem to handle this in credo itself?
Looks like
Credo.CLI.Output.UI.wrap_at/2
would be a good place to add such a safety conversion step.I'd be happy to work on a PR if we think this is worth pursuing.
The text was updated successfully, but these errors were encountered: