Skip to content
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

Escape Prisma command when running with script on Linux #1561

Merged
merged 10 commits into from
Nov 14, 2023
Merged

Conversation

infomiho
Copy link
Contributor

@infomiho infomiho commented Nov 7, 2023

Closes #1486

@infomiho infomiho changed the title Escape all of the shell command call args Escape Prisma command when running with script on Linux Nov 7, 2023
@infomiho infomiho marked this pull request as ready for review November 7, 2023 16:44
waspc/waspc.cabal Outdated Show resolved Hide resolved
waspc/src/Wasp/Generator/DbGenerator/Jobs.hs Outdated Show resolved Hide resolved
waspc/src/Wasp/Generator/DbGenerator/Jobs.hs Outdated Show resolved Hide resolved
waspc/src/Wasp/Util/ShellCommand.hs Outdated Show resolved Hide resolved
waspc/src/Wasp/Util/ShellCommand.hs Outdated Show resolved Hide resolved
@@ -0,0 +1,22 @@
module Wasp.Util.ShellCommand where
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 quite cool, I never used IsString!

I like the concept you used here, it is quite neat. So basically we have this notion of Shell command argument, and we can say if it is quoted or not, and we carry this knowledge around, and then can act on it.

What I found tricky is:

  1. There are no comments in this file explaining the reasoning behind it and what it is for. It is somewhat obvious, but I don't think it is obvious enough.
  2. Continuing on above, I think the reason it is not obvious enough is that usecase feels quite trivial. If I want args quoted, why don't I continue using String and just add quotes to it? Ok, I guess this gives more knowledge, so you can avoid quoting already quoted arg, or you can unquote already quoted arg (although that feels a bit weird, why was it quoted then, but ok, maybe we know somebody else will quote it). Still, I think it is a bit confusing so explanation would help.
  3. Using it above in the Jobs.hs feels a bit like overkill. Basically we need to quote these two args that are paths. And in one situation we need to quote them, in other we don't. But now we have to introduce this new type in all of the args there. But, not all of them, just some of them -> its not like we are using it across the whole codebase, just here. Feels weird that we are using it just in the small part of the codebase, how do we choose? When should I use this? Btw, isn't there a simpler solution -> can't we just quote those paths and that is it? Is it a problem if they are also quoted in that situation where they shouldn't be quoted, or will it just work?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So, the problem we have is the following: we need the same command in a slightly different ways for Linux and for MacOS.

MacOS

  • The arguments should be a list of arguments
  • The paths passed into the prisma command MUST NOT be quoted

Linux

  • The arguments are concatenated into a single string
  • The paths MUST be quoted (since they can have spaces in them)

I'll try to simplify the solution and make it very local (it will only affect the array of prisma db migrate args and nothing else).

Copy link
Member

Choose a reason for hiding this comment

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

Nice, this is much simpler now!

I left some small comments but otherwise it is good.

I would possibly consider skipping this file here, ShellCommand.hs, and just inlining this function quoteArg where it is used, since it is so niche / local, I don't think we benefit much from having it here in a separate file.

@infomiho
Copy link
Contributor Author

infomiho commented Nov 13, 2023

@Martinsos I've simplified the impl, tested it

Before

Screenshot 2023-11-13 at 12 12 37

After

Screenshot 2023-11-13 at 12 13 28

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.

Approved! Left some comments, but all is good already, so handle them as you like and all good from my side!

Comment on lines 96 to 106
["migrate", "status", "--schema", SP.fromAbsFile schema]
[ "migrate",
"status",
"--schema",
SP.fromAbsFile schema
]
Copy link
Member

Choose a reason for hiding this comment

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

If you really like it better in multiple lines fine, but I liked it better in one line, found it easier to read. And since it has nothing to do with this PR maybe we could revert it? Same goes for other couple of functions in this file.

Comment on lines 54 to 60
-- NOTE(miho): Since we are running the Prisma command using `script` and we are doing it
-- in two different ways (MacOS and Linux), we have to take care of quoting the paths
-- differently.
-- * MacOS - we are passing the command as multiple arguments, so we MUST NOT quote the paths.
-- * Linux - we are passing the command as one argument, so we MUST quote the paths.
buildPrismaMigrateCmd quoteArg =
[ quoteArg $ absPrismaExecutableFp projectDir,
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
-- NOTE(miho): Since we are running the Prisma command using `script` and we are doing it
-- in two different ways (MacOS and Linux), we have to take care of quoting the paths
-- differently.
-- * MacOS - we are passing the command as multiple arguments, so we MUST NOT quote the paths.
-- * Linux - we are passing the command as one argument, so we MUST quote the paths.
buildPrismaMigrateCmd quoteArg =
[ quoteArg $ absPrismaExecutableFp projectDir,
-- NOTE(miho): Since we are running the Prisma command using `script` and we are doing it
-- in two different ways (MacOS and Linux), we have to take care of quoting the path arguments
-- differently.
-- * MacOS - we are passing the command as multiple arguments, so we MUST NOT quote the path arguments.
-- * Linux - we are passing the command as one argument, so we MUST quote the path arguments.
buildPrismaMigrateCmd :: (String -> String) -> [String]
buildPrismaMigrateCmd argQuoter =
[ argQuoter $ absPrismaExecutableFp projectDir,

@@ -0,0 +1,22 @@
module Wasp.Util.ShellCommand where
Copy link
Member

Choose a reason for hiding this comment

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

Nice, this is much simpler now!

I left some small comments but otherwise it is good.

I would possibly consider skipping this file here, ShellCommand.hs, and just inlining this function quoteArg where it is used, since it is so niche / local, I don't think we benefit much from having it here in a separate file.

@infomiho infomiho merged commit 4db82bf into main Nov 14, 2023
4 checks passed
@infomiho infomiho deleted the miho-path-space branch November 14, 2023 12:32
martinovicdev pushed a commit to martinovicdev/wasp that referenced this pull request Nov 15, 2023
martinovicdev pushed a commit to martinovicdev/wasp that referenced this pull request Nov 24, 2023
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-cli command not handling white-space in path while running app
2 participants