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

Small fixes in telemetry and plugin init #113

Merged
merged 4 commits into from
Jul 2, 2023

Conversation

Yshayy
Copy link
Contributor

@Yshayy Yshayy commented Jun 29, 2023

@Yshayy Yshayy requested a review from royra July 2, 2023 09:06
Copy link
Collaborator

@royra royra left a comment

Choose a reason for hiding this comment

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

LGTM, see minor comments

log.debug(`project: ${projectName}`)
const envId = flags.id ?? await findAmbientEnvId(projectName)

const [envId, userModel] = flags.id ? [flags.id, { name: flags.id }] : await (async () => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

envId is incorrect here - missing branch suffix.
what is this fixing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The case of using down --id without docker/compose. (#114)

Copy link
Collaborator

Choose a reason for hiding this comment

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

if the project name is only needed for the debug.log call, I suggest removing it to simplify:

Suggested change
const [envId, userModel] = flags.id ? [flags.id, { name: flags.id }] : await (async () => {
const envId = flags.id ?? await findAmbientEnvId((await this.ensureUserModel()).name)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That was the variable before.
const envId = flags.id ?? await findAmbientEnvId(projectName)


const wrappedHook: OclifHook<'init'> = async function wrappedHook(...args) {
try {
const { id } = args[0]
Copy link
Collaborator

Choose a reason for hiding this comment

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

IMO this function shouldn't include any logic besides wrapping with try..catch, you can move the id check to the hook itself.

@@ -71,7 +72,7 @@ export const childProcessStdoutPromise = async (
return orderedOutput(output).stdout().toString('utf-8').trim()
}

export const spawnPromise = (
export const spawnPromise = async (
Copy link
Collaborator

Choose a reason for hiding this comment

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

redundant async

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The async isn't redundant, if spawn logic throw the error is not wrapped.
Ideally, any function that return a Promise should give a strong guarantee that the exception is always wrapped in the promise return value.
async force that, for example:

await ((function(){ throw "abc"; return Promise.resolve(5)}()).catch(e=> { }))

throws "abc"

await ((async function(){ throw "abc"; return Promise.resolve(5)}()).catch(e=> { }))

doesn't throw

packages/core/src/compose/client.ts Outdated Show resolved Hide resolved
packages/core/src/compose/client.ts Show resolved Hide resolved
packages/core/src/compose/client.ts Outdated Show resolved Hide resolved
packages/core/src/telemetry/machine-id.ts Show resolved Hide resolved
@royra royra self-requested a review July 2, 2023 09:21
@Yshayy
Copy link
Contributor Author

Yshayy commented Jul 2, 2023

Went with standard approach:
standard/standard#1442
mightyiam/eslint-config-love#253

Remote no-return-await (to avoid synchronous throws and use async stack-traces: https://v8.dev/blog/fast-async#improved-developer-experience) and force typescript to require the use of await when using async

@Yshayy Yshayy merged commit 10dfd5a into main Jul 2, 2023
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants