Skip to content

Bug in src/embed.js @getParser(node, opts) #810

Description

@shane-au-wade

Stack trace

TypeError: Cannot read properties of undefined (reading 'toLowerCase')
    at getParser (file:///Users/shane/repos/brm/node_modules/@prettier/plugin-xml/src/embed.js:56:21)
    at embed (file:///Users/shane/repos/brm/node_modules/@prettier/plugin-xml/src/embed.js:121:18)
    at recurse (file:///Users/shane/repos/brm/node_modules/prettier/index.mjs:22194:20)
    at AstPath.each (file:///Users/shane/repos/brm/node_modules/prettier/index.mjs:20791:9)
    at recurse (file:///Users/shane/repos/brm/node_modules/prettier/index.mjs:22189:16)
    at AstPath.call (file:///Users/shane/repos/brm/node_modules/prettier/index.mjs:20753:14)
    at recurse (file:///Users/shane/repos/brm/node_modules/prettier/index.mjs:22191:16)
    at AstPath.each (file:///Users/shane/repos/brm/node_modules/prettier/index.mjs:20791:9)
    at recurse (file:///Users/shane/repos/brm/node_modules/prettier/index.mjs:22189:16)
    at AstPath.call (file:///Users/shane/repos/brm/node_modules/prettier/index.mjs:20753:14)

console.log(node)

Screenshot 2024-08-12 at 11 23 49 AM

and the function is attempting to destructured some properties that don't exist

const { Name, attribute } = node; let parser = Name.toLowerCase();

thus we get the undefined TypeError

details of my machine

Screenshot 2024-08-12 at 11 27 04 AM

prettier config

{
  "trailingComma": "es5",
  "tabWidth": 2,
  "printWidth": 120,
  "semi": false,
  "singleQuote": false,

  "language": "postgresql",
  "keywordCase": "upper",

  "embeddedSqlTags": ["db.sql", "sql"],
  "embeddedSqlComments": ["db.sql", "sql"],

  "overrides": [
    {
      "files": ["*.md", "*.y?(a)ml"],
      "options": {
        "tabWidth": 2
      }
    }
  ],

  "plugins": ["prettier-plugin-embed", "prettier-plugin-sql", "@prettier/plugin-xml"]
}

command to reproduce

npx prettier --check . --log-level warn

Activity

  1. shane-au-wade commented on Aug 12, 2024

    @shane-au-wade
    Author

    I tried to fix this up, but I don't have much context of the upstream/downstream code.

  2. kddnewton commented on Jul 8, 2025

    @kddnewton
    Member

    Can you share the code you are trying to format?

  3. shane-au-wade commented on Jul 8, 2025

    @shane-au-wade
    Author

    @kddnewton this is a sanitized file but it is representative of the problem we are facing.

    I reran prettier in our environment and saw the same error message

    Image
    /**
     * SANITIZED VERSION FOR BUG REPORT - Original file contains actual authentication details
     * This file is ignored by prettier because the xml strings throw errors with prettier
     * I also noticed that the xml strings did not get formatted when I ran prettier on the file.
     * We need to audit the xml plugin + prettier embedded plugin, which seems to be broken
     */
    
    import type { Temporal } from "@js-temporal/polyfill"
    import { xml } from "lit-xml"
    
    /** Generic authentication passport template */
    export const authPassport = xml`
    <tokenPassport>
      <account>{AUTH_DOMAIN}</account>
      <consumerKey>{AUTH_CONSUMER_KEY}</consumerKey>
      <token>{AUTH_TOKEN_ID}</token>
      <nonce>{AUTH_NONCE}</nonce>
      <timestamp>{AUTH_TIMESTAMP}</timestamp>
      <signature algorithm='HMAC-SHA256'>{AUTH_SIGNATURE}</signature>
    </tokenPassport>`
    
    export const searchMoreWithId = (page: number, searchId: string) => xml`
    <?xml version='1.0' encoding='utf-8' ?>
      <soap-env:Envelope xmlns:soap-env='http://schemas.xmlsoap.org/soap/envelope/'>
      <soap-env:Header>
        ${authPassport}
      </soap-env:Header>
      <soap-env:Body>
        <searchMoreWithId>
          <searchId>${searchId}</searchId>
          <pageIndex>${page}</pageIndex>
        </searchMoreWithId>
      </soap-env:Body>
    </soap-env:Envelope>
    `
    
    export const employeeSearchData = (pageSize: number) => xml`
    <?xml version='1.0' encoding='utf-8' ?>
      <soap-env:Envelope xmlns:soap-env='http://schemas.xmlsoap.org/soap/envelope/'>
      <soap-env:Header>
        ${authPassport}
        <searchPreferences>
          <pageSize>${pageSize}</pageSize>
        </searchPreferences>
      </soap-env:Header>
      <soap-env:Body>
        <search>
          <searchRecord
              xmlns:ns12='urn:common_2023_2.platform.webservices.example.com'
              xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
              xsi:type='ns12:EmployeeSearchBasic'
            />
        </search>
      </soap-env:Body>
    </soap-env:Envelope>`
    
    export const billCustomFieldData = (
      pageSize: number,
      customFieldId: string,
      after?: Temporal.Instant,
      before?: Temporal.Instant
    ) => {
      const dateCriteria =
        after && before
          ? xml`
    <lastModifiedDate operator='within'>
      <searchValue>${after.toString()}</searchValue>
      <searchValue2>${before.toString()}</searchValue2>
    </lastModifiedDate>`
          : after
            ? xml`<lastModifiedDate operator='after'><searchValue>${after.toString()}</searchValue></lastModifiedDate>`
            : before
              ? xml`<lastModifiedDate operator='before'><searchValue>${before.toString()}</searchValue></lastModifiedDate>`
              : xml``
    
      return xml`
    <?xml version='1.0' encoding='utf-8' ?>
        <soap-env:Envelope xmlns:soap-env='http://schemas.xmlsoap.org/soap/envelope/'>
      <soap-env:Header>
        ${authPassport}
        <searchPreferences>
          <bodyFieldsOnly>false</bodyFieldsOnly>
          <returnSearchColumns>true</returnSearchColumns>
          <pageSize>${pageSize}</pageSize>
        </searchPreferences>
      </soap-env:Header>
      <soap-env:Body>
        <search>
          <searchRecord
                xsi:type='ns8:TransactionSearchAdvanced'
                xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
                xmlns:ns8='urn:sales_2023_2.transactions.webservices.example.com'
              >
            <criteria>
              <basic>
                ${dateCriteria}
                <type operator='anyOf'>
                  <searchValue>_vendorBill</searchValue>
                </type>
              </basic>
            </criteria>
            <columns>
              <basic>
                <internalId />
                <customFieldList
                      xsi:type='core:SearchColumnCustomFieldList'
                      xmlns:core='urn:core_2023_2.platform.webservices.example.com'
                    >
                  <core:customField internalId='${customFieldId}' xsi:type='core:SearchColumnSelectCustomField' />
                </customFieldList>
              </basic>
            </columns>
          </searchRecord>
        </search>
      </soap-env:Body>
    </soap-env:Envelope>`
    }
    
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions