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

Issue 672 #673

Merged
merged 21 commits into from
Aug 6, 2019
Merged

Issue 672 #673

merged 21 commits into from
Aug 6, 2019

Conversation

PopGoesTheWza
Copy link
Collaborator

Fixes #672

  • npm run test succeeds.
  • npm run lint succeeds.
  • Appropriate changes to README are included in PR.

PopGoesTheWza and others added 21 commits May 14, 2019 00:03
use forEach instead of map when return value is not used (google#614)
* dependencies clean-up

* types for child_process' spawnSync

* types for child_process' spawnSync + options fix

* linting
* relative rootDir support

* relative rootDir support (untrackedFiles behavior changed)

* relative rootDir doc changes
* prettier + sort imports

* splitLines types

* unused package 'connect'

* ucfirst, isOnline types

* ellipsize types

* redundant package 'fs-copy-file-sync'

* removing extra line

* // TODO

* packages dependencies update

* comment fix

* fixes

* nicer ellipsize typing

* better?
* regroup `inquirer` into a single file

* fix typo

* linting

* switch to `find-up`

* switch to `find-up` & `strip-bom`

* dependencies update

* findUp implementation fix

* enum accessor fix

* fs-extra & typescript dependency fix

* linting

* dependencies clean-up (again)

* non any cast
@PopGoesTheWza
Copy link
Collaborator Author

@grant if you prefer, I can change to always use ‘return logError(…)’ for clarity?

@grant
Copy link
Contributor

grant commented Aug 1, 2019

Thanks.
I'd rather see a smaller PRs that don't change functionality for refactoring.
If this breaks something, and we merge other PRs, it will be hard to revert.

For example, import changes should be included in this PR.

Added some comments.

@PopGoesTheWza
Copy link
Collaborator Author

Sorry but I unsure I fully understand your comment :)

  • this PR has no functional changes but only making the use of logError() homogeneous
  • regarding the import changes, I guess your are refering to how the import statements are sorted on top of each file. I am unsure why it happens (only on this repository!) but from day to day the vsc extension seems to change it sort order.

Just to be sure, package versions upgrade in package.json are best kept in distinct PR (unless when related to the other change in the PR obviously)

@@ -51,7 +47,7 @@ export async function getFunctionNames(script: script_v1.Script, scriptId: strin
// TODO: unnecessary export
export async function getProjectIdWithErrors() {
const projectId = await getProjectId(); // will prompt user to set up if required
if (!projectId) throw logError(null, ERROR.NO_GCLOUD_PROJECT);
Copy link
Contributor

Choose a reason for hiding this comment

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

So this throw specifically blocks the return from happening.

I don't know if the caller of getProjectIdWithErrors handles an empty return value, but probably not. I'll still throw here and elsewhere for this PR.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

logError() never returns to the caller but always ends the node process.
We could make a choice to:

  • rename it to something more descriptive like logErrorAndDie ;)
  • always throw logError

@@ -330,7 +329,7 @@ export async function checkOauthScopes(rc: ClaspToken) {
await oauthScopesPrompt()
.then(async (answers) => {
if (answers.doAuth) {
if (!rc.isLocalCreds) return logError(null, ERROR.NO_LOCAL_CREDENTIALS);
if (!rc.isLocalCreds) logError(null, ERROR.NO_LOCAL_CREDENTIALS);
Copy link
Contributor

Choose a reason for hiding this comment

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

Return is needed. Otherwise we try to auth with no credentials.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Same as above

@@ -65,10 +64,7 @@ export default async (cmd: { type: string; title: string; parentId: string; root
spinner.setSpinnerTitle(LOG.CREATE_PROJECT_START(title)).start();
try {
const { scriptId } = await getProjectSettings(true);
if (scriptId) {
logError(null, ERROR.NO_NESTED_PROJECTS);
process.exit(1);
Copy link
Contributor

Choose a reason for hiding this comment

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

Are we sure this isn't needed? I wouldn't add it unless it's necessary.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Same as above.
logError() now has an optional parameter it’ll use with process.exit()

getProjectSettings().then(projectSettings => {
console.log(`${LOG.OPEN_LINK(LOG.SCRIPT_LINK(projectSettings.scriptId))}\n`);
console.log(`${LOG.GET_PROJECT_ID_INSTRUCTIONS}\n`);
projectIdPrompt()
.then(answers => {
projectId = answers.projectId;
const dotfile = DOTFILE.PROJECT();
if (!dotfile) return reject(logError(null, ERROR.SETTINGS_DNE));
if (!dotfile) logError(null, ERROR.SETTINGS_DNE);
dotfile
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm pretty sure this will fail. Is this on purpose?

I don't know if all the cases are handled. Maybe we can explain the way this works in a comment?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Since logError always end by calling process.exit() it should not change anything.

I opened this issue/PR because in many places of the source, the usage of logError() was (misleadingly) hinting that it would return and resume execution (which doesn’t”t occur ever)

@grant grant merged commit ee16b6d into google:master Aug 6, 2019
@grant
Copy link
Contributor

grant commented Aug 6, 2019

Thanks.
I don't know why I was so confused by the return issue.

@PopGoesTheWza
Copy link
Collaborator Author

I initiated this PR just because of this, use of logError() was inducing confusion.
And after your review, I now wonder if renaming logError to logErrorAndExitProcess wouldn't help preventing any more confusion in the future.

@PopGoesTheWza PopGoesTheWza deleted the issue-672 branch August 6, 2019 15:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[refactor] usage of function logError varies alot
3 participants