adobe / aio-cli-plugin-app-dev

App Builder CLI - dev command
Apache License 2.0
0 stars 2 forks source link

fix: improper use of readFile to read the generated public cert #95

Closed shazron closed 3 months ago

shazron commented 3 months ago

Description

Running aio app dev results in this error:

TypeError [ERR_INVALID_ARG_TYPE]: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received an instance of Object
    at writeFile (node:fs:2269:5)
    at go$writeFile (/Users/shazron/Documents/git/work/adobe/aio-cli-plugin-app-dev/node_modules/graceful-fs/graceful-fs.js:138:14)
    at Object.writeFile (/Users/shazron/Documents/git/work/adobe/aio-cli-plugin-app-dev/node_modules/graceful-fs/graceful-fs.js:135:12)
    at /Users/shazron/Documents/git/work/adobe/aio-cli-plugin-app-dev/node_modules/universalify/index.js:9:12
    at new Promise (<anonymous>)
    at Object.writeFile (/Users/shazron/Documents/git/work/adobe/aio-cli-plugin-app-dev/node_modules/universalify/index.js:7:14)
    at Dev.getOrGenerateCertificates (/Users/shazron/Documents/git/work/adobe/aio-cli-plugin-app-dev/src/commands/app/dev/index.js:222:16)
    at async Dev.runOneExtensionPoint (/Users/shazron/Documents/git/work/adobe/aio-cli-plugin-app-dev/src/commands/app/dev/index.js:169:33)
    at async Dev.run (/Users/shazron/Documents/git/work/adobe/aio-cli-plugin-app-dev/src/commands/app/dev/index.js:59:7)
    at async Dev._run (/Users/shazron/Documents/git/work/adobe/aio-cli-plugin-app-dev/node_modules/@oclif/core/lib/command.js:311:22) {
  code: 'ERR_INVALID_ARG_TYPE'
}
 ›   Error: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView.
 ›   Received an instance of Object

This is because of a typo here (note the previous line): https://github.com/adobe/aio-cli-plugin-app-dev/blob/b7dfd5c5a169c49ba4a2c2c2b85faa6a22d7f701/src/commands/app/dev/index.js#L238

The typo resulted in evaluation using the comma operator -- the right most operand is returned.

This was not caught in the unit tests because we mock the return value.

Workaround

aio config del aio-dev.dev-keys
rm -rf dist/dev-keys
aio app dev # will error
aio app dev # will not error

How Has This Been Tested?

aio config del aio-dev.dev-keys
rm -rf dist/dev-keys
aio app dev # should not error

Types of changes

Checklist:

codecov[bot] commented 3 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 100.00%. Comparing base (b7dfd5c) to head (612d259). Report is 1 commits behind head on main.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #95 +/- ## ========================================= Coverage 100.00% 100.00% ========================================= Files 6 6 Lines 562 562 Branches 122 122 ========================================= Hits 562 562 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.