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

Backend produces messages inconsistent with protocol definition #11964

Open
kazcw opened this issue Jan 2, 2025 · 0 comments
Open

Backend produces messages inconsistent with protocol definition #11964

kazcw opened this issue Jan 2, 2025 · 0 comments

Comments

@kazcw
Copy link
Contributor

kazcw commented Jan 2, 2025

According the protocol, the tagValues and defaultValue fields of a SuggestionEntryArgument may have values or may be omitted, but must not be null. The current LS (8054ff7) may provide null for these fields; here's a (formatted) excerpt from a search/suggestionsDatabaseUpdates message:

{ 
  "type": "Add", 
  "id": 13260, 
  "suggestion": { 
    "type": "constructor", 
    "module": "Standard.Image.Histogram", 
    "name": "Value", 
    "arguments": [ 
      { 
        "name": "channel", 
        "reprType": "Standard.Base.Any.Any", 
        "isSuspended": false, 
        "hasDefault": false, 
        "defaultValue": null, 
        "tagValues": null 
      }, 
      { 
        "name": "data", 
        "reprType": "Standard.Base.Any.Any", 
        "isSuspended": false, 
        "hasDefault": false, 
        "defaultValue": null, 
        "tagValues": null 
      } 
    ], 
    "returnType": "Standard.Image.Histogram.Histogram", 
    "documentation": " PRIVATE\nThe histogram of a single image channel.\n\nArguments:\n- channel: The channel in the image for which this is a histogram.\n- data: The histogram data.", 
    "annotations": [], 
    "reexports": [] 
  } 
}

Proximal cause

When encoding, .dropNullValues from circe is applied to the top level of the object; however, it is non-recursive.

Solution

circe has a deepDropNullValues that might be an appropriate replacement.

Root cause

Currently, the protocol types are defined in three places: As Typescript code blocks in the Markdown protocol specification, with circe in the backend, and with zod in the frontend. Consistency of the protocol used by the backend and frontend is dependent on the backend and frontend developers carefully ensuring the respective protocol definitions are consistent with the protocol specification. Subtle differences, such as in the distinction between null or an omitted field, are hard to avoid and are likely to cause bugs at runtime.

Solution

To ensure backend and frontend are using the same protocol (and simplify making protocol changes), we could unify the protocol definitions:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: New
Development

No branches or pull requests

1 participant