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

[BUG] file.serialize mege_if_exists deserialization exception -> Malformed state return #61814

Closed
lkubb opened this issue Mar 21, 2022 · 0 comments · Fixed by #61815
Closed
Assignees
Labels
Bug broken, incorrect, or confusing behavior needs-triage

Comments

@lkubb
Copy link
Contributor

lkubb commented Mar 21, 2022

Description
When targeting file.serialize with merge_if_exists=True to a file that is improperly formatted, instead of displaying the error cause, salt will complain about a malformed state return.

Setup
M1 Mac, masterless minion (likely irrelevant)

Steps to Reproduce the behavior

This creates a malformed json file:
  file.managed:
    - name: /tmp/exception.json
    - contents: |
        {
            "foo": "bar",
        }

This throws an exception instead of failing with cause description:
  file.serialize:
    - name: /tmp/exception.json
    - serializer: json
    - merge_if_exists: true
    - dataset:
        baz: true

Expected behavior
A clear and concise description of what went wrong: Failed to deserialize existing data: Expecting value: line 1 column 1 (char 0)

Screenshots

           ID: This throws an exception instead of failing with cause description
     Function: file.serialize
         Name: /tmp/exception.json
       Result: False
      Comment: An exception occurred in this state: Malformed state return. Data must be a dictionary type.
      Changes:

Versions Report

Salt Version:
          Salt: 3004

Dependency Versions:
          cffi: 1.14.6
      cherrypy: unknown
      dateutil: 2.8.0
     docker-py: Not Installed
         gitdb: 4.0.5
     gitpython: 3.1.12
        Jinja2: 2.11.3
       libgit2: Not Installed
      M2Crypto: Not Installed
          Mako: 1.1.4
       msgpack: 1.0.2
  msgpack-pure: Not Installed
  mysql-python: Not Installed
     pycparser: 2.19
      pycrypto: Not Installed
  pycryptodome: 3.9.8
        pygit2: Not Installed
        Python: 3.7.4 (default, Oct 12 2021, 12:57:44)
  python-gnupg: 0.4.4
        PyYAML: 5.4.1
         PyZMQ: 18.0.1
         smmap: 3.0.2
       timelib: 0.2.4
       Tornado: 4.5.3
           ZMQ: 4.3.1

System Versions:
          dist: darwin 21.3.0
        locale: UTF-8
       machine: x86_64
       release: 21.3.0
        system: Darwin
       version: 10.16 x86_64

Additional context
Already diagnosed and found a fix, PR incoming:

https://github.com/saltstack/salt/blob/1ebaed1ff0e1ccf5fb67050de19ce642ab8d28d2/salt/states/file.py#L7755-L7760s sets ret correctly, but still opts to return False.

@lkubb lkubb added Bug broken, incorrect, or confusing behavior needs-triage labels Mar 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug broken, incorrect, or confusing behavior needs-triage
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants