Skip to content

Errors with dockerfile parser #441

Closed

Description

@zdm

Hi.
I updated to 0.17.1 and trying to use new dockerfile parser to format dockerfile.
But it dies with error:

panic: runtime error: index out of range
RuntimeError: unreachable
    at main.runtime.runtimePanicAt (wasm://wasm/main-004aad7a:wasm-function[211]:0x10867)
    at main.runtime.lookupPanic (wasm://wasm/main-004aad7a:wasm-function[18]:0x1dff)
    at main.github.com/reteps/dockerfmt/lib.formatRun (wasm://wasm/main-004aad7a:wasm-function[1788]:0xc012b)
    at main.github.com/reteps/dockerfmt/lib.FormatNode (wasm://wasm/main-004aad7a:wasm-function[1780]:0xbe2c2)
    at main.(*github.com/reteps/dockerfmt/lib.ParseState).processNode (wasm://wasm/main-004aad7a:wasm-function[1778]:0xbde86)
    at main.(*github.com/reteps/dockerfmt/lib.ParseState).processNode (wasm://wasm/main-004aad7a:wasm-function[1778]:0xbdf31)
    at main.formatBytes.command_export (wasm://wasm/main-004aad7a:wasm-function[1797]:0xc6475)
    at formatDockerfileContents (file:///d:/projects/softvisio-node/cli/node_modules/@reteps/dockerfmt/dist/format.js:20:27)
    at async printAstToDoc (file:///d:/projects/softvisio-node/cli/node_modules/prettier/index.mjs:20124:16)
    at async coreFormat (file:///d:/projects/softvisio-node/cli/node_modules/prettier/index.mjs:20538:14)

Dockerfile:

RUN \
    # cleanup
    ls -la

Seems, that such comments syntax is not supported.

Activity

  1. JounQin commented on Apr 10, 2025

    @JounQin
    Member
  2. JounQin commented on Apr 10, 2025

    @JounQin
    Member

    @zdm Would you like to PR to add a failing test case?

  3. zdm commented on Apr 10, 2025

    @zdm
    Author

    Sorry, I am overloaded by 200% with my ongoing work. Will be busy for a month or even more.

  4. JounQin commented on Apr 10, 2025

    @JounQin
    Member

    Seems fixed with @reteps/dockerfmt v0.3.2

    exports[`parser and printer > should format 441.Dockerfile fixtures > 441.Dockerfile 1`] = `
    "RUN # cleanup
    ls -la
    "
    `;

  5. JounQin commented on Apr 10, 2025

    @JounQin
    Member

    @zdm Please try prettier-plugin-sh v0.17.2

  6. zdm commented on Apr 10, 2025

    @zdm
    Author

    Still has problems. No errors, but output is corrupted:

    RUN \
        # install dependencies
        NODE_ENV=production npm install-clean \
        \
        # cleanup
        && /usr/bin/env bash <(curl -fsSL https://raw.githubusercontent.com/softvisio/scripts/main/env-build-node.sh) cleanup
    

    become:

    RUN # install dependencies
    # cleanup
    
  7. JounQin commented on Apr 10, 2025

    @JounQin
    Member
    Image

    @zdm I cann't reproduce it.

    exports[`parser and printer > should format 441.Dockerfile fixtures > 441.Dockerfile 1`] = `
    "RUN # install dependencies
    NODE_ENV=production npm install-clean \\
    # cleanup
    && /usr/bin/env bash <(curl -fsSL https://raw.githubusercontent.com/softvisio/scripts/main/env-build-node.sh) cleanup
    "
    `;

    What's your dockerfile's name?

  8. added a commit that references this issue on Apr 10, 2025
  9. zdm commented on Apr 10, 2025

    @zdm
    Author

    What's your dockerfile's name?

    Dockerfile, or can be docketfile, both names are correct.

  10. added a commit that references this issue on Apr 10, 2025
  11. JounQin commented on Apr 10, 2025

    @JounQin
    Member

    Please provided reproduction then.

  12. added a commit that references this issue on Apr 10, 2025
  13. zdm commented on Apr 10, 2025

    @zdm
    Author

    Plugin version: 0.17.2

    Source ``dockerfile`:

    FROM ghcr.io/zerocluster/node/app
    
    RUN \
        # install dependencies
        NODE_ENV=production npm install-clean \
        \
        # cleanup
        && /usr/bin/env bash <(curl -fsSL https://raw.githubusercontent.com/softvisio/scripts/main/env-build-node.sh) cleanup
    

    First run result:

    FROM ghcr.io/zerocluster/node/app
    
    RUN # install dependencies
     NODE_ENV=production npm install-clean \
     # cleanup
     && /usr/bin/env bash <(curl -fsSL https://raw.githubusercontent.com/softvisio/scripts/main/env-build-node.sh) cleanup
    

    Second run result:

    FROM ghcr.io/zerocluster/node/app
    
    RUN # install dependencies
    # cleanup
    && /usr/bin/env bash <(curl -fsSL https://raw.githubusercontent.com/softvisio/scripts/main/env-build-node.sh) cleanup
    

    Third run result::

    FROM ghcr.io/zerocluster/node/app
    
    RUN # install dependencies
    # cleanup
    
  14. JounQin commented on Apr 10, 2025

    @JounQin
    Member

    OK... I'll take a look tomorrow.

  15. 2 remaining items

  16. reteps commented on Apr 10, 2025

    @reteps
    Contributor
  17. zdm commented on Apr 10, 2025

    @zdm
    Author

    i will test when it will be published

  18. JounQin commented on Apr 10, 2025

    @JounQin
    Member

    i will test when it will be published

    You can test it right now by upgrading the upstream package without changes in this repo.

  19. zdm commented on Apr 10, 2025

    @zdm
    Author

    I tested.
    Works not, with one exception.
    It doesn't respect indentation configuration.

    Result:

    RUN \
     # install dependencies
     NODE_ENV=production npm install-clean \
     # cleanup
     && /usr/bin/env bash <(curl -fsSL https://raw.githubusercontent.com/softvisio/scripts/main/env-build-node.sh) cleanup
    

    I have 4 spaces indentation configured, but it always make 1 space indent, which is not very readable and breaks prettier behavior.

  20. reteps commented on Apr 10, 2025

    @reteps
    Contributor
  21. zdm commented on Apr 10, 2025

    @zdm
    Author

    So, what I should do? )))
    I am confused.
    I can help to test it, but I an not familiar with this project internals.
    I am just using prettier and this plugin, I don't know, how one package invoke other and with what options.

  22. JounQin commented on Apr 11, 2025

    @JounQin
    Member

    @zdm Sorry for the confusion, a runnable reproduction repo is required for this. It's hard to tell without debugging.

  23. JounQin commented on Apr 11, 2025

    @JounQin
    Member

    exports[`parser and printer > should format 441.Dockerfile fixtures - {"indent":4} > 441.Dockerfile 1`] = `
    "RUN \\
    # install dependencies
    NODE_ENV=production npm install-clean \\
    # cleanup
    && /usr/bin/env bash <(curl -fsSL https://raw.githubusercontent.com/softvisio/scripts/main/env-build-node.sh) cleanup
    "
    `;

    Seems indeed not working expected, I'll make a simple reproduction for dockerfmt.

    See reteps/dockerfmt#21 (comment)

  24. MoKhajavi75 commented on Apr 22, 2025

    @MoKhajavi75

    same here
    is there a way to disable this for dockerfiles?

  25. JounQin commented on Apr 22, 2025

    @JounQin
    Member

    same here is there a way to disable this for dockerfiles?

    @MoKhajavi75 You can set parser: sh to override the default parser with overrides as https://prettier.io/docs/configuration#configuration-overrides.

  26. added a commit that references this issue on May 9, 2025
    1ea6700
  27. zdm commented on May 9, 2025

    @zdm
    Author

    Just updated and tested
    It removes indentation, so it is not fixed

    diff after dockerfile parsed was applied:

     RUN \
    -    # install dependencies
    -    NODE_ENV=production npm install-clean \
    -    \
    -    # cleanup
    -    && /usr/bin/env bash <(curl -fsSL https://raw.githubusercontent.com/softvisio/scripts/main/env-build-node.sh) cleanup
    + # install dependencies
    + NODE_ENV=production npm install-clean \
    + # cleanup
    + && /usr/bin/env bash <(curl -fsSL https://raw.githubusercontent.com/softvisio/scripts/main/env-build-node.sh) cleanup
    
  28. JounQin commented on May 9, 2025

    @JounQin
    Member

    At least it won't error anymore, this is just a workaround temporarily, the root cause is from the upstream, so the true fix can only happen in the upstream.

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