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

Failed yaml edit #55

Closed
sigurdm opened this issue Aug 10, 2023 · 2 comments · Fixed by #75 or #76
Closed

Failed yaml edit #55

sigurdm opened this issue Aug 10, 2023 · 2 comments · Fixed by #75 or #76
Labels
type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@sigurdm
Copy link
Contributor

sigurdm commented Aug 10, 2023

Reproduction:

> dart --version
Dart SDK version: 3.1.0-227.0.dev (dev) (Sun Jun 18 18:21:21 2023 -0700) on "linux_x64"
# pubspec.yaml
name: sample
version: 0.1.0
environment:
  sdk: ^3.0.0
dependencies:
dev_dependencies:
  retry:

No pubspec.lock.

dart pub add retry
"retry" was found in dev_dependencies. Removing "retry" and adding it to dependencies instead.
Assertion failed: (package:yaml_edit) Modification did not result in expected result.

# YAML before edit:
> name: sample
> version: 0.1.0
> environment:
>   sdk: ^3.0.0
> dependencies:
>   retry: ^3.1.2
> dev_dependencies:
>   retry:

# YAML after edit:
> name: sample
> version: 0.1.0
> environment:
>   sdk: ^3.0.0
> dependencies:
>   retry: ^3.1.2
> :

Please file an issue at:
https://github.com/dart-lang/yaml_edit/issues/new?labels=bug
package:yaml_edit/src/editor.dart 565:7  YamlEditor._performEdit
package:yaml_edit/src/editor.dart 432:5  YamlEditor.remove
package:pub/src/command/add.dart 722:24  AddCommand._updatePubspec
package:pub/src/command/add.dart 239:28  AddCommand.runProtected
This is an unexpected error. The full log and other details are collected in:

    /usr/local/google/home/sigurdm/.pub-cache/log/pub_log.txt

Consider creating an issue on https://github.com/dart-lang/pub/issues/new
and attaching the relevant parts of that log file.
@sigurdm sigurdm added the type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) label May 2, 2024
@sigurdm
Copy link
Contributor Author

sigurdm commented May 2, 2024

@jonasfj we should look into this.

jonasfj added a commit to jonasfj/yaml_edit that referenced this issue May 2, 2024
Fixes dart-lang#55.

When the value is empty the `SourceSpan` for the `YamlNode` representing
the value in a map points to the colon.

Example:
```yaml
foo:
  bar:
```

The `YamlNode` for `foo.bar` has a value of `null` and starts and ends
at the colon `:` following `bar`. This means that removal might leave
the colon behind, which causes invalid YAML.

We have the same issue when removing `foo.bar` from the following YAML
document:

```yaml
foo:
  baz: true
  bar:
```

However, in this case, we have a hack that ensures we always strip away
the any comments that follows `bar`. We do this by deleting up-to the
next newline. If we apply the same hack when removing `foo.bar` in the
first example, then it works.

One could argue that it works by accident, but it's kind of desired that
trailing comments are removed, when the value they are trailing is
removed.
@jonasfj jonasfj mentioned this issue May 2, 2024
jonasfj added a commit that referenced this issue May 2, 2024
Fix removal of last key from map in block-mode when value is empty.

Fixes #55.

When the value is empty the `SourceSpan` for the `YamlNode` representing
the value in a map points to the colon.

Example:
```yaml
foo:
  bar:
```

The `YamlNode` for `foo.bar` has a value of `null` and starts and ends
at the colon `:` following `bar`. This means that removal might leave
the colon behind, which causes invalid YAML.

We have the same issue when removing `foo.bar` from the following YAML
document:

```yaml
foo:
  baz: true
  bar:
```

However, in this case, we have a hack that ensures we always strip away
the any comments that follows `bar`. We do this by deleting up-to the
next newline. If we apply the same hack when removing `foo.bar` in the
first example, then it works.

One could argue that it works by accident, but it's kind of desired that
trailing comments are removed, when the value they are trailing is
removed.
@jonasfj jonasfj reopened this May 6, 2024
@jonasfj
Copy link
Member

jonasfj commented May 6, 2024

If the file ends immediately after retry:, instead of there being a newline this causes issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
2 participants