When using the listServiceLevelObjectives function, an UnhandledPromiseRejectionWarning occurs: The error message returned is "3 INVALID_ARGUMENT

Hey there, I'm struggling to retrieve a list of SLOs in my Google Cloud project via the REST API using TypeScript. Unfortunately, I keep running into an error message. Could you lend me a hand with this? The error reads:

(node:47173) UnhandledPromiseRejectionWarning: Error: 3 INVALID_ARGUMENT: Received invalid service name: [object Object] at Object.callErrorFromStatus (/Users/mpanova/workspace/node/monitoring-automation/node_modules/@grpc/grpc-js/src/call.ts:81:24) at Object.onReceiveStatus (/Users/mpanova/workspace/node/monitoring-automation/node_modules/@grpc/grpc-js/src/client.ts:334:36) at Object.onReceiveStatus (/Users/mpanova/workspace/node/monitoring-automation/node_modules/@grpc/grpc-js/src/client-interceptors.ts:434:34) at Object.onReceiveStatus (/Users/mpanova/workspace/node/monitoring-automation/node_modules/@grpc/grpc-js/src/client-interceptors.ts:397:48) at Http2CallStream.outputStatus (/Users/mpanova/workspace/node/monitoring-automation/node_modules/@grpc/grpc-js/src/call-stream.ts:230:22) at Http2CallStream.maybeOutputStatus (/Users/mpanova/workspace/node/monitoring-automation/node_modules/@grpc/grpc-js/src/call-stream.ts:280:14) at Http2CallStream.endCall (/Users/mpanova/workspace/node/monitoring-automation/node_modules/@grpc/grpc-js/src/call-stream.ts:263:12) at Http2CallStream.handleTrailers (/Users/mpanova/workspace/node/monitoring-automation/node_modules/@grpc/grpc-js/src/call-stream.ts:412:10) at ClientHttp2Stream.emit (events.js:314:20) at emit (internal/http2/core.js:291:8) at processTicksAndRejections (internal/process/task_queues.js:83:22) at emitUnhandledRejectionWarning (internal/process/promises.js:168:15) at processPromiseRejections (internal/process/promises.js:247:11) at processTicksAndRejections (internal/process/task_queues.js:94:32)

To be frank, I'm relatively new to TypeScript as I usually work with Java, so perhaps the error is something simple that I am overlooking.

This is the code snippet causing issues: list_slos.ts in source directory

export module ListSloTest {
    export async function listSlos(projectId: string) {
        // Imports the Google Cloud client library
        const monitoring = require('@google-cloud/monitoring');

        // Creates a client
        const client = new monitoring.ServiceMonitoringServiceClient();

        const request = {
            parent: client.projectPath(projectId),
        };
        console.log(projectId)

        const [slos] = await client.listServiceLevelObjectives({parent: request});

        slos.forEach((slo: any) => {
            console.log('');
            console.log('slo: %j', slo);
    });
**list_slos.ts in test directory**
import "mocha";
import * as assert from "assert";
import {ListSloTest} from "../dist/list_slos";

describe("list_slos",()=>{

    before(function () {
        process.env = {GOOGLE_CLOUD_PROJECT: 'projectId',
            GOOGLE_APPLICATION_CREDENTIALS: '/somePath/projectId-a17ce3d7c2e6.json'};
    });

    it("should list slos in given project",()=>{

        ListSloTest.listSlos("projectId");
        //console.log("hello, world!")
        assert.ok(true);

    });

});

I typically compile the code from the source directory to the dist directory before running tests on it.

Answer №1

Solved! Here is the updated request:

const requestData = client.getPathToProjectService(projectId, serviceName);

This solution is specific to version 2.1.1 of @google-cloud/monitoring. Unfortunately, I couldn't locate an example for this version, only for 1.7 which is incompatible with 2.1.1.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips for converting numerical values in a JSON object to strings within a TypeScript interface

{ "id": 13, "name": "horst", } in order to interface A { id: string; name: string; } When converting JSON data of type A to an object, I expected the conversion of id from number to string to happen automatically. However, it doesn' ...

Corrected typing mistakes using vuex

Currently, I am working on a project using Vue 3 and TypeScript. One issue I am facing is related to vuex. I have created a file named vuex.d.ts to access $store inside Components: import { Store } from 'vuex'; import { State } from '@/stor ...

Error in Typescript: The property 'a' is not defined in the type 'A'

Here is an example of the different types I am working with: type Place = { address: string } type Location = { latLng: string } type User = { name: string } & (Place | Location) When attempting to parse the data using this structure, I enco ...

The child element is triggering an output event that is in turn activating a method within the parent

I am currently utilizing @Output in the child component to invoke a specific method in the parent component. However, I am encountering an issue where clicking on (click)="viewPromotionDetails('Learn more')" in the child component is al ...

Converting Http Client GET response into an array of objects with specified type

I have a model set up for the data I am retrieving through a GET request, and my goal is to map this data to an array of Player objects. This is an example of the response data received from the API: [ { Id: 1 PlayerName: "Dave", ...

Error: Unable to parse string in URI within vscode API

Console LOG displays: \Users\skhan\Library\Application Support\Code\User\summary.txt The loop is used to replace the slashes. It works fine in Windows but not in Ubuntu and Mac. This is an example on OSX 10.11.6. Howev ...

The property slider in the d3 slider package is not found in the type 'types of d3'

I attempted to integrate a d3 slider into my d3 chart in Angular 2. I installed the d3slider package using the command: npm install --save @types/d3.slider. However, when trying to access the method "d3.slider()", an error occurred stating that "property ...

Having trouble extracting value from another component or dealing with an architectural issue?

Just recently delving into Angular, I embarked on this journey last week with a small programming foundation. My current project involves creating a simple blog application where I need to pass a value from the root (app.component.ts) to my component tag " ...

Is there a way to eliminate the initial and final double quotes within Angular 4?

Similar to JavaScript, TypeScript also uses either double quotes (") or single quotes (') to enclose string data. I have data coming from the backend that includes HTML content. Here is an example of my API response: <p>afjhjhfsd</p> Wh ...

Combining and consolidating a unique observable array that originated from the ngrx state tree

Upon making an API call, the data is retrieved and processed through ngrx-effects before being stored in the state tree. From there, I can access the data in my angular component's constructor and utilize rxjs methods like mergeMap and reduce to forma ...

Different ways to fulfill the extends type interface requirement in TypeScript

Hey there, I'm looking to create reusable hooks for API requests. Here's the code I have so far: interface DataResponse<Data> { data: Data[]; } export const useRequestInfiniteHooks = <T extends DataResponse<T>>() => { co ...

What is the best way to configure eslint or implement tslint and prettier for typescript?

In my React/Redux project, I recently started integrating TypeScript into my workflow. The eslint configuration for the project is set up to extend the airbnb eslint configurations. Here's a snippet of my current eslint setup: module.exports = { // ...

Embedding Globalize.js into an Angular component

Hey there! I'm currently working on building an Angular 4 application that needs to support L10n. I've decided to incorporate globalize into my project. Below is a snippet of my App component: import { Component, OnInit } from '@angular/c ...

What is the best way to implement persistStore in Redux-Toolkit?

Here is my setup: import AsyncStorage from '@react-native-async-storage/async-storage' import { persistStore, persistReducer } from 'redux-persist'; import { configureStore } from "@reduxjs/toolkit"; import { searchReducer } f ...

Angular input field displaying X

Hey everyone, I'm currently working with Angular and typescript. I have a requirement to hide the first 8 characters that the user enters and only show the remaining 4 characters. Update: I have included a link to the Stackblitz demo Stackblitz <i ...

Database records failing to update after deployment

After deploying my next js site using Vercel, I encountered an issue with the functionality related to adding, getting, editing, and deleting data from MongoDB. Although all functions were working perfectly locally, once deployed, I noticed that while I co ...

Deactivate multiple textareas within a loop by utilizing JQuery/Typescript and KnockoutJS

I am working on a for loop that generates a series of textareas with unique ids using KO data-binding, but they all share the same name. My goal is to utilize Jquery to determine if all the textareas in the list are empty. If they are, I want to disable al ...

A guide on transferring received data from dataService within the parent component to the child component in Angular2

Within the context of my application, there exists a parent component named app-parent and a child component called app-child. In app-parent, I retrieve data from a DataService. @Component({ selector: 'app-parent', providers: [DataService] ...

Error message "ERR_FILE_NOT_FOUND" displayed in Ionic Dailymotion iframe player

While viewing the app on a browser, the video player functions properly. However, when accessed on a phone, the following error occurs. I suspect that the issue lies in the 'file:' prefix, but I am unable to remove it using string.replace('f ...

Anonymous function bundle where the imported namespace is undefined

Here is the code snippet I am working with: import * as Phaser from 'phaser'; new Phaser.Game({ width:300, height:300, scale: { mode: Phaser.Scale.FIT, }, type: Phaser.AUTO, scene: { create() {} }, }); Upon compi ...