Skip to content

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

Open

Description

@apintorp

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

Activity

  1. maietta commented on Mar 22, 2023

    @maietta

    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

  2. apintorp commented on Mar 23, 2023

    @apintorp
    Author

    I remove CRs
    image

    and also remove everything
    image

    still happen same issue

  3. maietta commented on Mar 23, 2023

    @maietta

    How are you attempting to deploy your app?

  4. apintorp commented on Mar 23, 2023

    @apintorp
    Author

    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.

  5. maietta commented on Mar 23, 2023

    @maietta

    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.

  6. apintorp commented on Mar 23, 2023

    @apintorp
    Author

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions