Skip to content

Conversation

@sodic
Copy link
Contributor

@sodic sodic commented Nov 24, 2025

Description

Fixes #3307

image

Type of change

  • 🔧 Just code/docs improvement
  • 🐞 Bug fix
  • 🚀 New/improved feature
  • 💥 Breaking change

Checklist

  • I tested my change in a Wasp app to verify that it works as intended.

  • 🧪 Tests and apps:

    • I added unit tests for my change.
      • The current function is not tested and setting up the infrastructure to test it would be too time-consuming (at least for me).
    • (if you fixed a bug) I added a regression test for the bug I fixed.
    • (if you added/updated a feature) I added/updated e2e tests in examples/kitchen-sink/e2e-tests.
    • (if you added/updated a feature) I updated the starter templates in waspc/data/Cli/templates, as needed.
    • (if you added/updated a feature) I updated the example apps in examples/, as needed.
      • (if you updated examples/tutorials) I updated the tutorial in the docs (and vice versa).
  • 📜 Documentation:

    • (if you added/updated a feature) I added/updated the documentation in web/docs/.
  • 🆕 Changelog: (if change is more than just code/docs improvement)

    • I updated waspc/ChangeLog.md with a user-friendly description of the change.
    • (if you did a breaking change) I added a step to the current migration guide in web/docs/migration-guides/.
    • I bumped the version in waspc/waspc.cabal to reflect the changes I introduced.

@sodic sodic temporarily deployed to fly-deploy-test November 24, 2025 13:51 — with GitHub Actions Inactive
@sodic sodic temporarily deployed to fly-deploy-test November 24, 2025 14:02 — with GitHub Actions Inactive
userClientEnvVars <-
liftIO $
combineEnvVarsWithEnvFiles (Args.clientEnvironmentVariables args) (Args.clientEnvironmentFiles args)
when (null userClientEnvVars && null userServerEnvVars) $ throwError noEnvVarsSpecifiedErrorMsg
Copy link
Contributor Author

@sodic sodic Nov 24, 2025

Choose a reason for hiding this comment

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

Since:

  • Our output is pretty noisy and warnings easily get lost
  • And @cprecioso said:

    There's no reasonable situation in which there wouldn't be any environment variables, as at a minimum we'd require the DATABASE_URL.

I decided to throw an error instead of a warning. This is how it looks like:

image

Potential caveats:

  • What if the user wants to test how their system behaves when it lacks all env vars? They'd have to pass in a dummy env var just to satisfy our check.

Reviewers: Let me know what you think. Do you think I should log a warning instead?

Copy link
Member

Choose a reason for hiding this comment

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

Seems reasonable to have error and not warning.

What if the user wants to test how their system behaves when it lacks all env vars?

I don't think we need to support that usecase

styleCode :: String -> String
styleCode = applyStyles [Bold]
styleCode "" = ""
styleCode str = ansiEscapeCode ++ getAnsiCodeFor Bold ++ str ++ ansiEscapeCode ++ ansiResetBoldDimCode
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had to change this because the applyStyles command is too agressive - it resets all the styles, not just the ones it applied.

Here's an example, this is what happens when I use the old version of styleCode inside an error message:

3397

Copy link
Member

Choose a reason for hiding this comment

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

True! I think when I was implementing it, I was just using the general reset code. Which now that you say this, doesn't sounds great hah, because you can't envelop one style with another style.

I see you instead used a specific reset (I dind't even know those exist, awesome).
Why not, while at it, fix the applyStyles function so it resets specific ansii codes, and fix it for good, instead of doing this exception here? Sounds like a simple fix?

Copy link
Contributor Author

@sodic sodic Dec 4, 2025

Choose a reason for hiding this comment

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

I tried it, it was too fiddly to fix and test (some do have their own reset codes, others don't, different treatment for colors and styles, etc.). Details explained here: #3412 (comment). And I'll create an issue.

Also, I'd probably rather use a library for it then implement it here, and that's a seprate discussion which also kind of started in that other thread.

applyStyles [] str = str
applyStyles _ "" = ""
applyStyles styles str = foldl' applyStyle str styles ++ ansiEscapeCode ++ ansiResetCode
applyStyles styles str = foldl' applyStyle str styles ++ ansiEscapeCode ++ ansiResetAllCode
Copy link
Contributor Author

Choose a reason for hiding this comment

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

As mentioned in the other comment, this command is too agressive. ansiResetAllCode removes all the styles including the ones this command didn't apply, which makes it unsuable in all pre-styled text (e.g., error messages).

There are more specific reset codes depending on what you want to reset (source). Unfortunately, only styles (bold, underline) have specific reset codes. Colors only have "reset all."

Anyway, we should:

  • Ideally find a library that does this for us.
  • If that's impossible, refactor our internal library:
    • Differentiate between style and color
    • Implement something like minimalResetFor :: Style -> String or do something even better to get more control.
    • Encapuslate ansiEscapeCode. Callers shouldn't have to import both getAnsiCodeFor and ansiEscapeCode. They are never used independently.

I'll create an issue for this.

Copy link
Member

Choose a reason for hiding this comment

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

Together with #3403, I was thinking that we for sure need to either use a library, or make ourselves some API like

errorMessage = CliMsg $ Bold "Wasp Server: " <> Yellow appName <> " is not defined"

and then we compute the ansi codes at print time (or strip them if needed)

Copy link
Member

Choose a reason for hiding this comment

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

It seems prettyprinter and prettyprinter-ansi-terminal is what optparse-applicative uses, we might want to reuse too.

Copy link
Member

Choose a reason for hiding this comment

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

We could define default color that is used to reset colors, and then specific resets for styles, that would probably work well enough for now.

I remember I was looking at other libraries, but I think I found them complicated or didn't like the API, so I did it manually, that it is simple enough. But I am ok for using library of course.

@cprecioso you are suggesting we basically decorate the text with metadata but then later decide how to interpret it (style it, not style it, ...).
I like that, it sounds very nice. I am only wondering if it might complicate things too much, since these are not strings then, and we can't use normal functions to operate on them or print them. But maybe that is ok: because once we add ansi codes in, they are also not normal strings hah, so better not to be able to just simply operate on them. Yeah, I like this, it is semantically correct.

++ styleCode "wasp build start"
++ " without specifying any environment variables for the started apps (client and server)."
++ "\nThis is a mistake. Run "
++ styleCode "wasp build start --help"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It would be nice if I could draw the help command (i.e., wasp build start --help) without hardcoding it, but I don't think I can?

Copy link
Member

@cprecioso cprecioso Nov 25, 2025

Choose a reason for hiding this comment

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

Maybe using Options.Applicative.execParserPure can make the parser output the help text.
IMO this is nice-to-have but not key, so I'd try it and see if it can be easily done, skip it otherwise.

Copy link
Member

@Martinsos Martinsos Nov 27, 2025

Choose a reason for hiding this comment

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

What does it mean you could "draw" it? Aha, you mean refer to it somehow, so if its exact invocation changes, this is still correct?

Hm, yeah that would be really nice. We could certainly refactor our system to support this, but probably not worth it now.

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Nov 24, 2025

Deploying wasp-docs-on-main with  Cloudflare Pages  Cloudflare Pages

Latest commit: 40032af
Status: ✅  Deploy successful!
Preview URL: https://b65c0c60.wasp-docs-on-main.pages.dev
Branch Preview URL: https://filip-env-var-message.wasp-docs-on-main.pages.dev

View logs

@sodic sodic temporarily deployed to fly-deploy-test November 24, 2025 15:47 — with GitHub Actions Inactive
@sodic sodic temporarily deployed to fly-deploy-test November 24, 2025 16:25 — with GitHub Actions Inactive
@sodic sodic temporarily deployed to fly-deploy-test November 24, 2025 16:47 — with GitHub Actions Inactive
@sodic sodic marked this pull request as ready for review November 24, 2025 16:47
@sodic sodic requested review from Martinsos and cprecioso November 24, 2025 16:47
@FranjoMindek FranjoMindek changed the title Add error message when user doesn't specify env vars Add error message when user doesn't specify env vars in wasp build start Nov 24, 2025
userClientEnvVars <-
liftIO $
combineEnvVarsWithEnvFiles (Args.clientEnvironmentVariables args) (Args.clientEnvironmentFiles args)
when (null userClientEnvVars && null userServerEnvVars) $ throwError noEnvVarsSpecifiedMsg
Copy link
Member

Choose a reason for hiding this comment

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

something to think about:
if the user passes client envs but not server envs, that's incorrect. the opposite is probably fine. maybe we serve our users better by only checking server envs.
I'm open to being convinced otherwise.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hm, I didn't want to bake too many assumptions about how other parts of Wasp, or their app and its env vars work. Perhaps they have a client env var that's essential as well?

So my idea was to verify "Did the user manage to get at least one env var to one of the apps?"

  • If the answer is "no," then something is wrong and we warn them.
  • If the answer is "yes," then they know what to do, they know about the flags, and knowing about one flag makes the other obvious. If they forgot some (or all) necessary variables, the runtime will warn them.

We muddied the waters here by verifying env vars after resolution (discussion at #3412 (comment)), meaning we do perform a part of the runtime's job, but I don't think we should do more than that.

Copy link
Member

@Martinsos Martinsos left a comment

Choose a reason for hiding this comment

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

Quick review as per invite, I will let @cprecioso do the main reviewing/approving, I just commented on couple of things I might be relevant for.


### 🔧 Small improvements

- `wasp build start` now errors when users forget to specify environment variables ([#3412](https://github.com/wasp-lang/wasp/pull/3412))
Copy link
Member

Choose a reason for hiding this comment

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

errors

I thought we are just warning them? Are we sure we want to actually error, is that a bit too strong?

Copy link
Contributor Author

@sodic sodic Dec 4, 2025

Choose a reason for hiding this comment

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

Discussed here. Resolve this thread please and reply there if necessary :)

$ "You called "
++ styleCode "wasp build start"
++ " without specifying any environment variables for the started apps (client and server)."
++ "\nThis is a mistake. Run "
Copy link
Member

Choose a reason for hiding this comment

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

This is a mistake.

Hah this made me laugh. Sounds very short/harsh/robotic somehow.

Couldn't we offer some more information? I think we should explain why this is a mistake -> obviously they don't know, and while just telling them this is a mistake is a first step, but a bit extra info would be nice (even if full explanation is in wasp build start --help).

Copy link
Contributor Author

@sodic sodic Dec 4, 2025

Choose a reason for hiding this comment

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

Hm, what do you suggest we say? I personally wouldn't add anything else but am open to suggestions and will very likely accept them.

obviously they don't know

I'd argue that they do know that not sending env vars is a mistake. They just maybe don't know how to send them. Parts of this are already discussed here: #3412 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Btw, I managed to refer to the help command's text and now this is my output:
image

So you can suggest improvements on that. I can't change anything that comes after "Available options." That comes from the parser.


serverUrl' = defaultDevServerUrl
noEnvVarsSpecifiedMsg =
CommandError
Copy link
Member

Choose a reason for hiding this comment

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

So we are going for error, not for warning? I saw you say in another comment it will be warning + it makes sense to me it is warning. I can see it being an error though if we are 100% sure they might not have done this on purpose (are we?).

Copy link
Contributor Author

@sodic sodic Dec 4, 2025

Choose a reason for hiding this comment

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

Discussed here. Resolve this thread please and reply there if necessary :)

@sodic sodic temporarily deployed to fly-deploy-test December 4, 2025 19:47 — with GitHub Actions Inactive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

wasp build start: Show warning message when no environment variables were passed

4 participants