caprover / caprover-cli

Command Line Interface for https://github.com/caprover/caprover
72 stars 39 forks source link

captain-definition file is not a valid JSON! #134

Open apintorp opened 1 year ago

apintorp commented 1 year ago

What is the problem? When trying to deploy app via CLI, no matter all the format fixes we try, caprover cli keeps saying the definition file is not a valid Json

Steps to reproduce the problem: Just try to run the command over the attached file on zip

caprover deploy

Windows 11 Caprover Cli Version 2.2.3 Node Version v18.14.0

Output of the following command on your server: image captain-definition.zip

maietta commented 1 year ago

For those of you who don't want to download and extract the contents of the zip file, I've done this in a sandbox and provide the content of the captain-definition contained within:

{
  "schemaVersion": 2,
  "dockerfilePath": "./Dockerfile"
}

The contents of the file include CRLF Windows formatted return lines. The file needs to have these changed to normal line feed, or just LF. This would be denoted as a \n or would appear as LF in some editors.

image

apintorp commented 1 year ago

I remove CRs image

and also remove everything image

still happen same issue

maietta commented 1 year ago

How are you attempting to deploy your app?

apintorp commented 1 year ago

Ok, after reviewing the code I found out that on the file utils\ValidationsHandler.ts there is the function function validateDefinitionFile() to validate the captain-definition file.

There is this lines of code where specified that the file be will read it with encode utf8:

    content = JSON.parse(
        fs.readFileSync('./captain-definition', 'utf8')
    )

In my case my file was encoded on UTF8-BOM so the wrong encoding make the JSON.Parserand fail. After convert it to UTF8 now it works. The git commit shows that the file was changed after the conversion. image

I was about to start writing a fix to this but I ignore what are the side effects about this particular issue since it can actually break the caprover server.

So I just let you know guys what I found so you can decide the best approach to it.

maietta commented 1 year ago

Byte Order Marked files have crept up periodically in the last 25+ years of my software development experience. Often, they appear after the corrupt file transfers over FTP or going between Mac and PC. I've also seen them created out of thin air by editing an existing file in Nodepad.exe in Windows.

Super annoying. I'm glad it's solved.

apintorp commented 1 year ago

Now that you mention Windows Notepad.exe, I saw when the developer create the captain-definition file and, guest what? He use it to created the file.

Please add a warning on the documentation that don't create or edit the files with Windows Notepad.

Thanks so much for your help @maietta