Skip to content

fix: prevent defaults being set to undefined, and interpret numbers a…#1861

Merged
nedvedba merged 2 commits intodevelfrom
1860-DAPS-bug-fix-proto3-undefined-default-values-artifact
Feb 23, 2026
Merged

fix: prevent defaults being set to undefined, and interpret numbers a…#1861
nedvedba merged 2 commits intodevelfrom
1860-DAPS-bug-fix-proto3-undefined-default-values-artifact

Conversation

@JoshuaSBrown
Copy link
Collaborator

@JoshuaSBrown JoshuaSBrown commented Feb 20, 2026

…nd enums as strings.

Ticket

Description

How Has This Been Tested?

Artifacts (if appropriate):

Tasks

  • - A description of the PR has been provided, and a diagram included if it is a new feature.
  • - Formatter has been run
  • - CHANGELOG comment has been added
  • - Labels have been assigned to the pr
  • - A reviwer has been added
  • - A user has been assigned to work on the pr
  • - If new feature a unit test has been added

Summary by Sourcery

Bug Fixes:

  • Ensure defaults are populated and numeric and enum values are interpreted as strings when transforming protobuf messages to plain objects.

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Feb 20, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Ensures incoming protobuf messages are converted to plain JavaScript objects with defaults and with longs/enums represented as strings before being passed to the message handler, avoiding undefined default fields and normalizing numeric/enum representations.

Sequence diagram for protobuf message handling and normalization

sequenceDiagram
    participant CoreSocket
    participant MessageDispatcher
    participant TypeResolver
    participant ProtobufType
    participant Handler

    CoreSocket->>MessageDispatcher: on message(msg, msg_info, which_field, ctx, correlation_id)
    MessageDispatcher->>MessageDispatcher: set g_ctx_next = ctx
    alt msg is not null
        MessageDispatcher->>TypeResolver: resolve_type(msg_info, which_field)
        alt which_field is set
            TypeResolver->>TypeResolver: lookup in g_msg_by_id using which_field
            TypeResolver-->>MessageDispatcher: resolved type from g_msg_by_id
        else no which_field
            TypeResolver-->>MessageDispatcher: resolved type from msg_info.type
        end
        alt resolve_type exists
            MessageDispatcher->>ProtobufType: toObject(msg, defaults true, longs String, enums String)
            ProtobufType-->>MessageDispatcher: normalized plain object msg
        else no resolve_type
            MessageDispatcher-->>MessageDispatcher: msg unchanged
        end
    else msg is null
        MessageDispatcher-->>MessageDispatcher: skip normalization
    end
    MessageDispatcher->>Handler: f(msg)
Loading

File-Level Changes

Change Details Files
Normalize protobuf message instances into plain objects with defaults and stringified longs/enums before invoking the handler function.
  • Determine the protobuf type to use for conversion from msg_info.type or by resolving the field entry when which_field is present.
  • Guard the conversion logic so it only runs when a message and a resolvable type are available.
  • Convert the protobufjs message to a plain object via type.toObject with options { defaults: true, longs: String, enums: String } and pass the resulting object into the downstream handler.
web/datafed-ws.js

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • The Object.values(g_msg_by_id).find(...) lookup inside the message handler will run on every message and could be expensive if g_msg_by_id is large; consider precomputing a field_name → type map or otherwise caching this resolution for the hot path.
  • Before calling Object.values(g_msg_by_id), it may be safer to guard against g_msg_by_id being null/undefined to avoid runtime errors in edge cases where the global map is not yet initialized.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The `Object.values(g_msg_by_id).find(...)` lookup inside the message handler will run on every message and could be expensive if `g_msg_by_id` is large; consider precomputing a `field_name → type` map or otherwise caching this resolution for the hot path.
- Before calling `Object.values(g_msg_by_id)`, it may be safer to guard against `g_msg_by_id` being `null`/`undefined` to avoid runtime errors in edge cases where the global map is not yet initialized.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@nedvedba nedvedba merged commit 354bd19 into devel Feb 23, 2026
11 checks passed
nedvedba added a commit that referenced this pull request Feb 23, 2026
#1861) (#1866)

* fix: prevent defaults being set to undefined, and interpret numbers and enums as strings.

* chore: Auto-format JavaScript files with Prettier

Co-authored-by: Joshua S Brown <joshbro42867@yahoo.com>
nedvedba added a commit that referenced this pull request Feb 23, 2026
* fix: prevent defaults being set to undefined, and interpret numbers a… (#1861)

* fix: prevent defaults being set to undefined, and interpret numbers and enums as strings.

* chore: Auto-format JavaScript files with Prettier

* fix: version numbers from proto3 messages follow camel case. (#1868)

---------

Co-authored-by: Joshua S Brown <joshbro42867@yahoo.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants