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

yamlfmt Fails to Parse Block Scalars with Initial Newline #213

Open
marcoroth opened this issue Oct 27, 2024 · 2 comments
Open

yamlfmt Fails to Parse Block Scalars with Initial Newline #213

marcoroth opened this issue Oct 27, 2024 · 2 comments
Labels
yaml_v3_problem A bug in the underlying yaml library. These issues are vastly harder to fix.

Comments

@marcoroth
Copy link

marcoroth commented Oct 27, 2024

yamlfmt encounters an error when parsing YAML files that contain block scalars (|-) with an initial newline after the block scalar indicator. This results in a parsing failure with the following error message:

❯ yamlfmt file.yml
encountered the following formatting errors:
file.yml: yaml: line 3: did not find expected key

The issue occurs when the YAML content is formatted as follows:

# file.yml

- id: item-1
  description: |-
  
    A lot of 

    multi-line

    copy here.

However, if the initial newline after the |- is removed, the cotent is getting parsed correctly:

# file.yml

- id: item-1
  description: |-
    A lot of 

   multi-line

   copy here.

Expected Behavior

yamlfmt should correctly parse and format YAML content that includes an initial newline after a block scalar indicator (|-). As far as I can tell this seems to be supported in YAML.

Steps to Reproduce

  1. Create a YAML file (file.yml) with the following content:
  - id: item-1
    description: |-
    
      A lot of 

     multi-line

     text here.
  1. Run yamlfmt on the file:
yamlfmt file.yml
  1. Observe the parsing error:
encountered the following formatting errors:
file.yml: yaml: line 3: did not find expected key
@braydonk braydonk added the yaml_v3_problem A bug in the underlying yaml library. These issues are vastly harder to fix. label Oct 30, 2024
@braydonk
Copy link
Collaborator

braydonk commented Oct 30, 2024

Hi @marcoroth thanks for opening an issue.

These types of newline nuances are fraught with complications, and I've lost count of the number of times over the years I've tried to fix them and come up short. This is probably going to fall into the same bucket of problems that it's unlikely I'm going to fix any time soon. Thank you for the additional data, it's good to know more edge cases where the library screws this up. I can't promise this will be fixed any time soon though, sorry.

@marcoroth
Copy link
Author

Hey @braydonk, thanks for the reply and the openness - this goes a long way. I can work around it for now, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
yaml_v3_problem A bug in the underlying yaml library. These issues are vastly harder to fix.
Projects
None yet
Development

No branches or pull requests

2 participants