googleapis / googleapis/google-cloud-node
Error "3 INVALID_ARGUMENT: Invalid resource field value in the request." when awaiting long-running operation
- Dominant language
- TypeScript
- Stars
- 3.2k
- Forks
- 712
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 99
Description
When programmatically creating a cloud function, I get the error "3 INVALID_ARGUMENT: Invalid resource field value in the request." when awaiting the long-running operation using the provided `promise()` call as described in the [sample code](https://github.com/googleapis/google-cloud-node/blob/main/packages/google-cloud-functions/samples/generated/v1/cloud_functions_service.create_function.js#L56). I can see that the cloud function is actually created correctly in the Google Cloud Console, so the problem appears to only relate to checking the status of the operation.
#### Environment details
- which product (packages/*): @google-cloud/functions
- OS: Windows 10
- Node.js version: 18.16.0
- npm version: 9.8.1
- google-cloud-node version: 2.5.0
#### Steps to reproduce
Create a file `debug.js` with the content below. Make sure to update the variables `projectId`, `location` and `keyFilePath` with valid values. Add required dependencies with `npm install @google-cloud/functions got jszip`.
```javascript
const { CloudFunctionsServiceClient } = require('@google-cloud/functions')
const got = require('got')
const JSZip = require('jszip')
run()
async function run() {
const projectId = 'my-project-id'
const location = 'my-location'
const keyFilePath = '/path/to/my-key.json'
const parent = `projects/${projectId}/locations/${location}`
const client = new CloudFunctionsServiceClient({
keyFile: keyFilePath,
})
const [uploadUrlResponse] = await client.generateUploadUrl({ parent })
const { uploadUrl } = uploadUrlResponse
if (!uploadUrl) throw new Error('Failed to create upload URL')
const zip = new JSZip()
zip.file(
'index.js',
`
module.exports.run = async (req, res) => {
res.send('Hello World!')
}`.trim(),
)
const zipBuffer = await zip.generateAsync({ type: 'nodebuffer' })
await got.put(uploadUrl, {
body: zipBuffer,
headers: {
// https://cloud.google.com/functions/docs/reference/rest/v1/projects.locations.functions/generateUploadUrl
'content-type': 'application/zip',
'x-goog-content-length-range': '0,104857600',
},
})
const [longRunningOperation] = await client.createFunction({
location: parent,
function: {
availableMemoryMb: 1024,
entryPoint: 'run',
httpsTrigger: {},
ingressSettings: 'ALLOW_ALL',
name: `${parent}/functions/my-debug-function`,
runtime: 'nodejs14',
sourceUploadUrl: uploadUrl,
},
})
try {
const [createdFunction] = await longRunningOperation.promise()
console.log(createdFunction)
} catch (error) {
console.error(error)
}
}
```
Execute `debug.js` with NodeJS:
```bash
$ node debug.js
Error: 3 INVALID_ARGUMENT: Invalid resource field value in the request.
at callErrorFromStatus (C:\debug\node_modules\@grpc\grpc-js\build\src\call.js:31:19)
at Object.onReceiveStatus (C:\debug\node_modules\@grpc\grpc-js\build\src\client.js:192:76)
at Object.onReceiveStatus (C:\debug\node_modules\@grpc\grpc-js\build\src\client-interceptors.js:360:141)
at Object.onReceiveStatus (C:\debug\node_modules\@grpc\grpc-js\build\src\client-interceptors.js:323:181)
at C:\debug\node_modules\@grpc\grpc-js\build\src\resolving-call.js:94:78
at process.processTicksAndRejections (node:internal/process/task_queues:77:11)
for call at
at ServiceClientImpl.makeUnaryRequest (C:\debug\node_modules\@grpc\grpc-js\build\src\client.js:160:32)
at ServiceClientImpl. (C:\debug\node_modules\@grpc\grpc-js\build\src\make-client.js:105:19)
at C:\debug\node_modules\google-gax\build\src\operationsClient.js:95:29
at C:\debug\node_modules\google-gax\build\src\normalCalls\timeout.js:44:16
at OngoingCallPromise.call (C:\debug\node_modules\google-gax\build\src\call.js:67:27)
at NormalApiCaller.call (C:\debug\node_modules\google-gax\build\src\normalCalls\normalApiCaller.js:34:19)
at C:\debug\node_modules\google-gax\build\src\createApiCall.js:84:30 {
code: 3,
details: 'Invalid resource field value in the request.',
metadata: Metadata {
internalRepr: Map(4) {
'endpoint-load-metrics-bin' => [Array],
'grpc-server-stats-bin' => [Array],
'google.rpc.errorinfo-bin' => [Array],
'grpc-status-details-bin' => [Array]
},
options: {}
},
statusDetails: [
ErrorInfo {
metadata: [Object],
reason: 'RESOURCE_PROJECT_INVALID',
domain: 'googleapis.com'
}
],
reason: 'RESOURCE_PROJECT_INVALID',
domain: 'googleapis.com',
errorInfoMetadata: {
method: 'google.longrunning.Operations.GetOperation',
service: 'cloudfunctions.googleapis.com'
}
}
```
Contributor guide
Assessment
This issue has not been assessed yet.