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

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

Open
apintorp opened this issue Mar 22, 2023 · 6 comments
Open

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

apintorp opened this issue Mar 22, 2023 · 6 comments

Comments

@apintorp
Copy link

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
Copy link

maietta commented Mar 22, 2023

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
Copy link
Author

I remove CRs
image

and also remove everything
image

still happen same issue

@maietta
Copy link

maietta commented Mar 23, 2023

How are you attempting to deploy your app?

@apintorp
Copy link
Author

apintorp commented Mar 23, 2023

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
Copy link

maietta commented Mar 23, 2023

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
Copy link
Author

apintorp commented Mar 23, 2023

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

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

No branches or pull requests

2 participants