Skip to content

Can't set NULL for Enum properties in Structs and Messages #385

@vladmu

Description

@vladmu

Based on the condition below the keyForValue call based on the default Enum's _keyForValue will always return null here for null obj

} else if (
(tClass.prototype instanceof Enum && tClass.keyForValue(obj) === null)
|| (tClass.prototype instanceof RpcStruct && obj !== null && obj.constructor !== tClass)
) {
throw new Error(`${obj.name} must be of type ${tClass.name}`);
}

Then because the condition is true, the code fails in line 145 with the error

TypeError: Cannot read property 'name' of null

Currently, all Enum classes use default _keyForValue for checks in their keyForValue methods so it is impossible to set null for all Enum properties (mandatory or optional) in all Structs and Messages

Steps to reproduce:

  1. Create for example the new instance of KeyboardProperties structure
  2. Try to set KeyboardLayout parameter (according to the spec this parameter is not mandatory) by calling setKeyboardLayout method with null value
  3. ER: null is successfully set, AR: the TypeError
new SDL.rpc.structs.KeyboardProperties().setKeyboardLayout(null) // this fails with TypeError: Cannot read property 'name' of null

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions