Skip to content

Ruff deserialization error #213

Description

@NorthLake

What happened?

Since 0.1.0-alpha-21, I get a MissingFieldException whenever ruff is executed by RyeCharm

Steps to reproduce

  1. Install an older version of Ruff that does not have the severity property (I'm using 0.12.8)
  2. Create a new project in PyCharm
  3. The error will already occur on loading the first Python file
  4. Type anything in a file to trigger ruff check and get the error again

Relevant log output or stack trace

error

kotlinx.serialization.MissingFieldException: Field 'severity' is required for type with serial name 'insyncwithfoo.ryecharm.ruff.linting.Diagnostic', but it was missing at path: $[0]
	at kotlinx.serialization.json.internal.StreamingJsonDecoder.decodeSerializableValue(StreamingJsonDecoder.kt:95)
	at kotlinx.serialization.encoding.AbstractDecoder.decodeSerializableValue(AbstractDecoder.kt:43)
	at kotlinx.serialization.encoding.AbstractDecoder.decodeSerializableElement(AbstractDecoder.kt:70)
	at kotlinx.serialization.json.internal.StreamingJsonDecoder.decodeSerializableElement(StreamingJsonDecoder.kt:168)
	at kotlinx.serialization.encoding.CompositeDecoder.decodeSerializableElement$default(Decoding.kt:539)
	at kotlinx.serialization.internal.CollectionLikeSerializer.readElement(CollectionSerializers.kt:80)
	at kotlinx.serialization.internal.AbstractCollectionSerializer.readElement$default(CollectionSerializers.kt:51)
	at kotlinx.serialization.internal.AbstractCollectionSerializer.merge(CollectionSerializers.kt:36)
	at kotlinx.serialization.internal.AbstractCollectionSerializer.deserialize(CollectionSerializers.kt:43)
	at kotlinx.serialization.json.internal.StreamingJsonDecoder.decodeSerializableValue(StreamingJsonDecoder.kt:69)
	at kotlinx.serialization.json.Json.decodeFromString(Json.kt:149)
	at insyncwithfoo.ryecharm.ruff.linting.CheckKt.runCheckCommand(Check.kt:45)
	at insyncwithfoo.ryecharm.ruff.linting.RuffAnnotator.doAnnotate(RuffAnnotator.kt:83)
	at insyncwithfoo.ryecharm.ruff.linting.RuffAnnotator.doAnnotate(RuffAnnotator.kt:49)
	at com.intellij.codeInsight.daemon.impl.ExternalToolPass.lambda$doAnnotate$1(ExternalToolPass.java:248)
	at com.intellij.codeInsight.daemon.impl.AnnotationSessionImpl.computeWithSession(AnnotationSessionImpl.java:91)
	at com.intellij.codeInsight.daemon.impl.AnnotationSessionImpl.computeWithSession(AnnotationSessionImpl.java:83)
	at com.intellij.codeInsight.daemon.impl.ExternalToolPass.doAnnotate(ExternalToolPass.java:246)
	at com.intellij.codeInsight.daemon.impl.ExternalToolPass.doAnnotate(ExternalToolPass.java:240)
	at com.intellij.codeInsight.daemon.impl.ExternalToolPass$1.lambda$run$3(ExternalToolPass.java:198)
	at com.intellij.codeInsight.daemon.impl.ExternalToolPass.runChangeAware(ExternalToolPass.java:313)
	at com.intellij.codeInsight.daemon.impl.ExternalToolPass$1.lambda$run$5(ExternalToolPass.java:198)
	at com.intellij.openapi.progress.util.BackgroundTaskUtil.lambda$runUnderDisposeAwareIndicator$15(BackgroundTaskUtil.java:387)
	at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$runProcess$2(CoreProgressManager.java:283)
	at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$executeProcessUnderProgress$14(CoreProgressManager.java:744)
	at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:819)
	at com.intellij.openapi.progress.impl.CoreProgressManager.computeUnderProgress(CoreProgressManager.java:775)
	at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:743)
	at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:87)
	at com.intellij.openapi.progress.impl.CoreProgressManager.runProcess(CoreProgressManager.java:267)
	at com.intellij.openapi.progress.util.BackgroundTaskUtil.runUnderDisposeAwareIndicator(BackgroundTaskUtil.java:382)
	at com.intellij.codeInsight.daemon.impl.ExternalToolPass$1.run(ExternalToolPass.java:196)
	at com.intellij.util.ui.update.Update.execute$suspendImpl(Update.kt:61)
	at com.intellij.util.ui.update.Update.execute(Update.kt)
	at com.intellij.util.ui.update.MergingUpdateQueue.executeUpdates$suspendImpl(MergingUpdateQueue.kt:386)
	at com.intellij.util.ui.update.MergingUpdateQueue.executeUpdates(MergingUpdateQueue.kt)
	at com.intellij.util.ui.update.MergingUpdateQueue$restart$1.invokeSuspend(MergingUpdateQueue.kt:345)
	at com.intellij.util.ui.update.MergingUpdateQueue$restart$1.invoke(MergingUpdateQueue.kt)
	at com.intellij.util.ui.update.MergingUpdateQueue$restart$1.invoke(MergingUpdateQueue.kt)
	at com.intellij.util.SingleAlarm$scheduleTask$1$1$1$2.invokeSuspend(SingleAlarm.kt:413)
	at com.intellij.util.SingleAlarm$scheduleTask$1$1$1$2.invoke(SingleAlarm.kt)
	at com.intellij.util.SingleAlarm$scheduleTask$1$1$1$2.invoke(SingleAlarm.kt)
	at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndspatched(Undispatched.kt:67)
	at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndispatchedOrReturn(Undispatched.kt:43)
	at kotlinx.coroutines.BuildersKt__Builders_commonKt.withContext(Builders.common.kt:157)
	at kotlinx.coroutines.BuildersKt.withContext(Unknown Source)
	at com.intellij.util.SingleAlarm$scheduleTask$1$1.invokeSuspend(SingleAlarm.kt:411)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:34)
	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:100)
	at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:610)
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runDefaultDispatcherTask(CoroutineScheduler.kt:1194)
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:906)
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:775)
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:762)
Caused by: kotlinx.serialization.MissingFieldException: Field 'severity' is required for type with serial name 'insyncwithfoo.ryecharm.ruff.linting.Diagnostic', but it was missing
	at kotlinx.serialization.internal.PluginExceptionsKt.throwMissingFieldException(PluginExceptions.kt:20)
	at insyncwithfoo.ryecharm.ruff.linting.Diagnostic.<init>(Results.kt:61)
	at insyncwithfoo.ryecharm.ruff.linting.Diagnostic$$serializer.deserialize(Results.kt:61)
	at insyncwithfoo.ryecharm.ruff.linting.Diagnostic$$serializer.deserialize(Results.kt:61)
	at kotlinx.serialization.json.internal.StreamingJsonDecoder.decodeSerializableValue(StreamingJsonDecoder.kt:69)
	... 53 more

stdout

[
  {
    "cell": null,
    "code": "D100",
    "end_location": {
      "column": 1,
      "row": 1
    },
    "filename": "C:\\Users\\user\\PycharmProjects\\PythonProject\\main.py",
    "fix": null,
    "location": {
      "column": 1,
      "row": 1
    },
    "message": "Missing docstring in public module",
    "noqa_row": 1,
    "url": "https://docs.astral.sh/ruff/rules/undocumented-public-module"
  },
  {
    "cell": null,
    "code": "ANN201",
    "end_location": {
      "column": 13,
      "row": 7
    },
    "filename": "C:\\Users\\user\\PycharmProjects\\PythonProject\\main.py",
    "fix": {
      "applicability": "unsafe",
      "edits": [
        {
          "content": " -> None",
          "end_location": {
            "column": 19,
            "row": 7
          },
          "location": {
            "column": 19,
            "row": 7
          }
        }
      ],
      "message": "Add return type annotation: `None`"
    },
    "location": {
      "column": 5,
      "row": 7
    },
    "message": "Missing return type annotation for public function `print_hi`",
    "noqa_row": 7,
    "url": "https://docs.astral.sh/ruff/rules/missing-return-type-undocumented-public-function"
  },
  {
    "cell": null,
    "code": "D103",
    "end_location": {
      "column": 13,
      "row": 7
    },
    "filename": "C:\\Users\\user\\PycharmProjects\\PythonProject\\main.py",
    "fix": null,
    "location": {
      "column": 5,
      "row": 7
    },
    "message": "Missing docstring in public function",
    "noqa_row": 7,
    "url": "https://docs.astral.sh/ruff/rules/undocumented-public-function"
  },
  {
    "cell": null,
    "code": "ANN001",
    "end_location": {
      "column": 18,
      "row": 7
    },
    "filename": "C:\\Users\\user\\PycharmProjects\\PythonProject\\main.py",
    "fix": null,
    "location": {
      "column": 14,
      "row": 7
    },
    "message": "Missing type annotation for function argument `name`",
    "noqa_row": 7,
    "url": "https://docs.astral.sh/ruff/rules/missing-type-function-argument"
  },
  {
    "cell": null,
    "code": "T201",
    "end_location": {
      "column": 10,
      "row": 9
    },
    "filename": "C:\\Users\\user\\PycharmProjects\\PythonProject\\main.py",
    "fix": {
      "applicability": "unsafe",
      "edits": [
        {
          "content": "pass",
          "end_location": {
            "column": 25,
            "row": 9
          },
          "location": {
            "column": 5,
            "row": 9
          }
        }
      ],
      "message": "Remove `print`"
    },
    "location": {
      "column": 5,
      "row": 9
    },
    "message": "`print` found",
    "noqa_row": 9,
    "url": "https://docs.astral.sh/ruff/rules/print"
  }
]

command
C:\Users\user\AppData\Local\Python\pythoncore-3.13-64\Scripts\ruff.exe check --no-fix --exit-zero --quiet - --output-format json --stdin-filename C:\Users\user\PycharmProjects\PythonProject\main.py --config C:\Users\user\path\to\custom\.ruff.toml

custom .ruff.toml

line-length = 150

[lint]
select = [
    "F", # pyflakes
    "E", # pycodestyle (Errors)
    "W", # pycodestyle (Warnings)
    "C90", # mccabe (complexity)
    "I", # isort
    "N", # pep8 naming
    "D", # pydocstyle
    "UP", # pyupgrade
    "ANN", # flake8-annotations
    "ASYNC", # flake8-async
    "A", # flake8-builtins
    "COM", # flake8-commas
    "C4", # flake8-comprehensions
    "DTZ", # flake8-datetimez
    "EM", # flake8-errmsg
    "EXE", # flake8-executable
    "ISC", # flake8-implicit-str-concat
    "ICN", # flake8-import-conventions
    "INP", # flake8-no-pep420
    "PIE", # flake8-pie
    "T20", # flake8-print
    "PYI", # flake8-pyi
    "PT", # flake8-pytest-style
    "Q", # flake8-quotes
    "RSE", # flake8-raise
    "RET", # flake8-return
    "SLF", # flake8-self
    "SLOT", # flake8-slot
    "SIM", # flake8-simplify
    "TID", # flake8-tidy-imports
    "INT", # flake8-gettext
    "ARG", # flake8-unused-arguments
    "ERA", # eradicate
    "PD", # pandas-vet
    "PGH", # pygrep-hooks
    "PL", # pylint
    "TRY", # tryceratops
    "FLY", # flyint
    "NPY", # NumPy-specific rules
    "AIR", # Airflow
    "PERF", # Perflint
    "RUF", # Ruff-specific rules
]
ignore = [
    # pydocstyle
    "D205", # Multi line module name
    "D401", # non-imperative-mood
    "D400", # ends-in-period
    "D404", # docstring-starts-with-this

    # flake8-commas
    "COM812", # missing-trailing-comma

    # flake8-implicit-str-concat (ISC)
    "ISC001", # implicit-str-concat-in-sequence

    # flake8-annotations
    "ANN003", # missing-type-kwargs

    # flake8-errmsg
    "EM101", # raw-string-in-exception
    "EM102", # f-string-in-exception

    # tryceratops
    "TRY003", # raise-vanilla-args

    # Ruff-specific rules (RUF)
    "RUF001", # ambiguous-unicode-character-string
    "RUF002", # ambiguous-unicode-character-docstring
    "RUF003", # ambiguous-unicode-character-comment

    # Ruff format compatibility (https://docs.astral.sh/ruff/formatter/#conflicting-lint-rules)
    "W191", # tab-indentation
    "E111", # indentation-with-invalid-multiple
    "E114", # indentation-with-invalid-multiple-comment
    "E117", # over-indented
    "D206", # indent-with-spaces
    "D300", # triple-single-quotes
    "Q000", # bad-quotes-inline-string
    "Q001", # bad-quotes-multiline-string
    "Q002", # bad-quotes-docstring
    "Q003", # avoidable-escaped-quote
    "COM812", # missing-trailing-comma
    "COM819", # prohibited-trailing-comma
    "ISC001", # single-line-implicit-string-concatenation
    "ISC002", # multi-line-implicit-string-concatenation
    "EXE002", # shebang-missing-executable-file
]

extend-select = [
    "D417",  # undocumented-param
]

[format]
quote-style = "double"
indent-style = "space"
docstring-code-format = true

[lint.pylint]
max-args = 9

[lint.pydocstyle]
convention = "numpy"

Operating system

Windows

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions