Giter VIP home page Giter VIP logo

Comments (6)

lugray avatar lugray commented on August 17, 2024

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.

colinbendell avatar colinbendell commented on August 17, 2024

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.

colinbendell avatar colinbendell commented on August 17, 2024

@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.

colinbendell avatar colinbendell commented on August 17, 2024

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:

  1. Whether formatting is a reason to interrupt CLI business logic
  2. 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 TESTenvironment 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.

lugray avatar lugray commented on August 17, 2024

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.

lugray avatar lugray commented on August 17, 2024

Closing as stale.

from cli-ui.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.