Repository navigation
Closed
Labels
corepriority: p2Moderately-important priority. Fix may not be included in next release.Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Description
A bug in the google-cloud package resulted in the following error:
Error: Sorry, we cannot connect to Cloud Services without a project ID. You may specify one with an environment variable named "GCLOUD_PROJECT". See https://googlecloudplatform.github.io/google-cloud-node/#/docs/guides/authentication for a detailed guide on creating an authenticated connection.
at Object.<anonymous> (/Users/gajus/Documents/dev/applaudience/movie-editor/node_modules/google-cloud/node_modules/@google-cloud/common/src/util.js:55:29)
at Module._compile (module.js:571:32)
at Module._extensions..js (module.js:580:10)
at Object.require.extensions.(anonymous function) [as .js] (/Users/gajus/Documents/dev/applaudience/movie-editor/node_modules/babel-register/lib/node.js:152:7)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
at Module.require (module.js:498:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/Users/gajus/Documents/dev/applaudience/movie-editor/node_modules/google-cloud/node_modules/@google-cloud/common/src/service-object.js:32:12)
The reason I am getting this error is this code block:
try {
authenticatedReqOpts = util.decorateRequest(
authenticatedReqOpts,
extend({ projectId: authClient.projectId }, config)
);
} catch(e) {
err = util.missingProjectIdError;
}
}Here catch assumes that any error that occurred in try is equivalent to missingProjectIdError.
Instead of blindly assuming what is the error, use instanceof check and a custom error constructor, e.g. https://github.com/gajus/xfetch/blob/0d8cd012354b0bb8b67162f74b2a9e126d3bdabb/src/attemptRequest.js#L52-L67.
Furthermore, what made it hard to debug is the lack stack trace (raised a separate issue #2068).
Metadata
Metadata
Assignees
Labels
corepriority: p2Moderately-important priority. Fix may not be included in next release.Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Activity
stephenplusplus commentedon Mar 9, 2017
What was the error that it mistook for a missing project ID error?
gajus commentedon Mar 9, 2017
Raising another issue for that.
gajus commentedon Mar 9, 2017
@stephenplusplus #2070
[-]Do not use catch-all without checking the instance of an error[/-][+]util.decorateRequest should confirm error is a missing project ID error[/+]fix: correct STORAGE_EMULATOR_HOST handling (#2069, #1314) (#2070)
Revert "fix: correct STORAGE_EMULATOR_HOST handling (#2069, #1314) (#…
chore(deps): update dependency @types/uuid to v10 (#2069)
fix: correct STORAGE_EMULATOR_HOST handling (googleapis#2069, googlea…
Revert "fix: correct STORAGE_EMULATOR_HOST handling (googleapis#2069, g…