Comments (6)
I'd be happy with raising a better exception, which could then be handled however you choose, but passing a non-supported format code is definitely an error and should be handled that way, so that it can be addressed properly.
from cli-ui.
I disagree here. Because it's often used in open source tools, any error that is shipped with formatting errors interrupts the user from completing a task. The task is interrupted and the user does not have any control or remediation. Users should only see stack traces and errors when a) there is an error state in their environment (which they need to remediate) or b) there is a bug in the tool which, if it were to proceed would have unexpected and potentially disastrous results. In both cases, an error is appropriate because the tool is not able to execute the desired business logic and outcome.
Formatted output, (and I'd argue other functionality like logging) are not critical errors that should interrupt the human. It is a bug, certainly, but it is a non critical bug. Interrupting the human on this 'technicality' is very disruptive and the human has no recourse except to wait for a bugfix. If the action the human is trying to accomplish is mission critical for them, then we have interrupted the workflow for no consequential reason.
It is like having your prescription rejected by the pharmacist because the doctor had a spelling mistake in the pharmacy address line. Embarrassing yes, but very inconvenient to the patient.
from cli-ui.
@lugray, A very real case and point is Shopify/shopify-cli#1388 where the developer was prevented from pushing a theme, interrupting their development flow because of a text formatting error. This cost the developer hours and it took 2weeks to repair. Treating formatting as errors, not warnings, has cost several developer-entrepreneur hundreds if not thousands of productivity dollars.
from cli-ui.
Yes, that's why I preserved the raised exception when TEST environment variable is set. Happy to extend that to another context that captures development and rake test environments. ENV['TEST'] was just a convenient environment variable that is commonly set but could use any other convention.
That covers running cli-ui tests, but we have no idea what conventions are used in consumers' test/dev environments. I'd be happy to accept a pr to incorporate support for CLI::UI::Formatter.ignore_invalid_codes = true. This would default to false, but consumers could choose to set it to true.
There are two arguments now:
- Whether formatting is a reason to interrupt CLI business logic
- Whether
ENV['TEST']
is sufficient enough to infer that the library is being used in dev or test mode by the calling CLI tool.
For {1}, I strongly maintain that the library should be generous - particularly when it is being invoked by a user. In this case it is not the developer that has integrated this library, but the end user who has a job to do. Interrupting business logic because of errors in the business logic is appropriate to avoid error states and corruption. Interrupting business logic because of cosmetic errors is not appropriate for the tool.
Further, we need to be generous to the developer who is integrating this library. They don't know what they don't know. They don't know that they could be bitten (like we were) by selecting an invalid colour. Requiring that the developer have foreknowledge to capture such states is a level of cognitive load that I don't want to push on to that developer. This is why, if anything I would advocate for ignore_invalid_codes = true
be the default and the user would have to opt-out of generous mode and opt-into strict mode.
As for {2}, we do know that the developer likely is implementing TESTs. The TEST
environment variable is commonly exposed and would be a good way to automatically trigger strict-mode. This way a CLI would error on formatting errors in their specs, but when the CLI is launched to production, this underlying library would return to generous mode.
from cli-ui.
I gave the puts "a" + 2
example because this could equally be seen as presentational logic. The format codes are a kind of DSL that we use within CLI::UI. If there's an error, it's an error. How you handle that in your code is up to you.
from cli-ui.
Closing as stale.
from cli-ui.
Related Issues (20)
- Spinner does not reset terminal fast enough when there's a lot of output HOT 2
- ANSI color code escaping for "ask" broken in Debian HOT 2
- Add example showing how to run a shell command with stdout redirected HOT 2
- Questions get duplicated when the message is too long HOT 6
- The ask color change my frame color.
- Can't prompt in a spinner
- Cant use gray color option for frame HOT 2
- Links to documentation are broken HOT 2
- Circular dependency warnings
- [Feature Request] Allow to debrief successful SpinGroups
- Add option to allow configuration of ask prompt instructions colour HOT 2
- Error interactive_options.rb:337:in `wait_for_user_input': Interrupt (Interrupt) HOT 2
- Cannot load such file - cli-ui-2.2.0/vendor/reentrant_mutex HOT 2
- Progress bar broken in 2.2? HOT 3
- Weak guarantees for `IO#write` override
- Intermittent prompt_test failure
- Radio buttons / checkboxes HOT 4
- Ability to fail the whole process if spinner fails
- CLI::UI.ask multi-line input
- SpinGroup hangs when used inside Prompt.ask HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cli-ui.