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

AppServiceRegistration.fromObject({ ... }) -> registration.outputAsYaml fails to serialize undefined value #33

Closed
MadLittleMods opened this issue Oct 30, 2020 · 0 comments · Fixed by #34
Assignees

Comments

@MadLittleMods
Copy link
Contributor

MadLittleMods commented Oct 30, 2020

Using AppServiceRegistration.fromObject({ ... }) followed by registration.outputAsYaml() results in yaml serializing error about pushEphemeral being undefined. See below for full cause.

Cause

Normally pushEphemeral is set to false.

But if you use AppServiceRegistration.fromObject({ ... }), it will look for obj["de.sorunome.msc2409.push_ephemeral"] in the object you pass in. For most people, the de.sorunome.msc2409.push_ephemeral key will be undefined.

Then when you try to save the registration to a YAML file via registrationConfig.outputAsYaml(), it will fail to serialize the undefined value.

Reproduction test case

AppServiceRegistration.fromObject({
  id: bridgeId,
  hs_token: hsToken,
  as_token: asToken,
  namespaces: {
    users: [
      {
        exclusive: true,
        regex: '@gitter_.*'
      }
    ],
    aliases: [],
    rooms: []
  },
  url: bridgeUrl,
  sender_localpart: senderLocalpart,
  rate_limited: true,
  protocols: null
});

console.log('registrationConfig', registrationConfig);
/*
registrationConfig AppServiceRegistration {
  url: 'http://host.docker.internal:9000',
  id:
   'xxx',
  hsToken:
   'xxx',
  asToken:
   'xxx',
  senderLocalpart: 'gitter-badger',
  rateLimited: true,
  pushEphemeral: undefined,
  namespaces: { users: [ [Object] ], aliases: [], rooms: [] },
  protocols: null,
  cachedRegex: {} }
*/

// This throws the `Uncaught exceptionYAMLException: unacceptable kind of an object to dump [object Undefined]` error
registrationConfig.outputAsYaml('output/gitter-matrix-as-registration.yaml');

Error:

Uncaught exceptionYAMLException: unacceptable kind of an object to dump [object Undefined]
    at writeNode (C:\Users\MLM\Documents\GitHub\matrix-appservice-bridge\node_modules\js-yaml\lib\js-yaml\dumper.js:779:13)
    at writeBlockMapping (C:\Users\MLM\Documents\GitHub\matrix-appservice-bridge\node_modules\js-yaml\lib\js-yaml\dumper.js:657:10)
    at writeNode (C:\Users\MLM\Documents\GitHub\matrix-appservice-bridge\node_modules\js-yaml\lib\js-yaml\dumper.js:750:9)
    at dump (C:\Users\MLM\Documents\GitHub\matrix-appservice-bridge\node_modules\js-yaml\lib\js-yaml\dumper.js:840:7)
    at Object.safeDump (C:\Users\MLM\Documents\GitHub\matrix-appservice-bridge\node_modules\js-yaml\lib\js-yaml\dumper.js:846:10)
    at AppServiceRegistration.outputAsYaml (C:\Users\MLM\Documents\GitHub\matrix-appservice-bridge\node_modules\matrix-appservice\lib\app-service-registration.js:186:64)
    at Object.<anonymous> (C:\Users\MLM\Documents\GitLab\webapp\modules\matrix-bridge\lib\bridge.js:44:22)

Relevant code


Found while working on https://gitlab.com/gitlab-org/gitter/webapp/-/merge_requests/2040

@MadLittleMods MadLittleMods changed the title AppServiceRegistration.fromObject({ ... }) -> registration.outputAsYaml fails to serialize AppServiceRegistration.fromObject({ ... }) -> registration.outputAsYaml fails to serialize undefined value Oct 30, 2020
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 a pull request may close this issue.

2 participants