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

Cannot read properties of undefined (reading 'status') at InfluxDBReporter.request \AppData\Roaming\npm\node_modules\newman-reporter-influxdb\src\influxdb-reporter.js:96:29 #41

Open
2 tasks done
Astitva2409 opened this issue Jan 23, 2024 · 1 comment
Labels
sweep Sweep your software chores

Comments

@Astitva2409
Copy link

Astitva2409 commented Jan 23, 2024

Details

Hi @vs4vijay, hope you are doing well. Currently i am facing an issue while running a postman collection using newman-influxdb-reporter.
I have used the below command:

newman run \Downloads\OrderServ\Basket\BasketCollection -e \Downloads\OrderServ\Basket\BasketEnvDesktopWeb -r influxdb --reporter-influxdb-server {server-ip-address}} --reporter-influxdb-mode http --reporter-influxdb-port 8086 --reporter-influxdb-org {org-name} --reporter-influxdb-version 2 --reporter-influxdb-username {user-name} --reporter-influxdb-password {password} --reporter-influxdb-name {bucket} --reporter-influxdb-measurement api_results

but i am getting the below error:

Starting collection: Orderserv Basket Management 1706014994995-0.031766501297362026
[+] Signing In to InfluxDB
\AppData\Roaming\npm\node_modules\newman-reporter-influxdb\src\influxdb-reporter.js:96
status: args.response.status,
^

TypeError: Cannot read properties of undefined (reading 'status')
at InfluxDBReporter.request \AppData\Roaming\npm\node_modules\newman-reporter-influxdb\src\influxdb-reporter.js:96:29)
at EventEmitter. (\AppData\Roaming\npm\node_modules\newman-reporter-influxdb\src\influxdb-reporter.js:28:105)
at EventEmitter.emit (node:events:525:35)
at Function.callbacks. [as request] (\AppData\Roaming\npm\node_modules\newman\lib\run\index.js:213:34)
at afterRequest (\AppData\Roaming\npm\node_modules\newman\node_modules\postman-runtime\lib\runner\extensions\http-request.command.js:86:35)
at \AppData\Roaming\npm\node_modules\newman\node_modules\postman-runtime\lib\runner\extensions\http-request.command.js:173:25
at onEnd (\AppData\Roaming\npm\node_modules\newman\node_modules\postman-runtime\lib\requester\requester.js:274:24)
at Request._callback (\AppData\Roaming\npm\node_modules\newman\node_modules\postman-runtime\lib\requester\requester.js:449:24)
at self.callback (\AppData\Roaming\npm\node_modules\newman\node_modules\postman-request\request.js:311:12)
at Request.emit (node:events:513:28)
at Request.onRequestError (\AppData\Roaming\npm\node_modules\newman\node_modules\postman-request\request.js:1199:8)
at ClientRequest.emit (node:events:513:28)
at Socket.socketErrorListener (node:_http_client:481:9)
at Socket.emit (node:events:513:28)
at emitErrorNT (node:internal/streams/destroy:157:8)
at emitErrorCloseNT (node:internal/streams/destroy:122:3)

Kindly assist in resolving the issue.

Checklist
  • Modify src/influxdb-reporter.jsdecd6d8 Edit
  • Running GitHub Actions for src/influxdb-reporter.jsEdit
@Astitva2409 Astitva2409 added the sweep Sweep your software chores label Jan 23, 2024
Copy link
Contributor

sweep-ai bot commented Jan 23, 2024

🚀 Here's the PR! #44

See Sweep's progress at the progress dashboard!
Sweep Basic Tier: I'm using GPT-4. You have 3 GPT-4 tickets left for the month and 1 for the day. (tracking ID: 658a41d1ee)

For more GPT-4 tickets, visit our payment portal. For a one week free trial, try Sweep Pro (unlimited GPT-4 tickets).

Tip

I can email you next time I complete a pull request if you set up your email here!


Actions (click)

  • ↻ Restart Sweep

GitHub Actions✓

Here are the GitHub Actions logs prior to making any changes:

Sandbox logs for adbb171
Checking src/influxdb-reporter.js for syntax errors... ✅ src/influxdb-reporter.js has no syntax errors! 1/1 ✓
Checking src/influxdb-reporter.js for syntax errors...
✅ src/influxdb-reporter.js has no syntax errors!

Sandbox passed on the latest develop, so sandbox checks will be enabled for this issue.


Step 1: 🔎 Searching

I found the following snippets in your repository. I will now analyze these snippets and come up with a plan.

Some code snippets I think are relevant in decreasing order of relevance (click to expand). If some file is missing from here, you can mention the path in the ticket description.

# newman-reporter-influxdb
InfluxDB reporter for [Newman](https://github.com/postmanlabs/newman) that sends the test results information to InfluxDB (1.x, 2.x) which can be used from Grafana to build dashboard.
<a href="https://www.npmjs.com/package/newman-reporter-influxdb">
<img alt="npm version" src="https://img.shields.io/npm/v/newman-reporter-influxdb.svg">
<img alt="npm downloads" src="https://img.shields.io/npm/dm/newman-reporter-influxdb.svg">
<img alt="code license" src="https://img.shields.io/github/license/vs4vijay/newman-reporter-influxdb">
<img alt="npm publish" src="https://github.com/vs4vijay/newman-reporter-influxdb/workflows/npm publish/badge.svg">
</a>
## Getting Started
1. Install `newman`
2. Install `newman-reporter-influxdb`
3. Install InfluxDB (Get the server address, port, database name, etc)
### Prerequisites
1. `node` and `npm`
2. `newman` - `npm install -g newman`
3. [InfluxDB](https://github.com/influxdata/influxdb)
---
## Installation
```console
npm install -g newman-reporter-influxdb
```
> Installation should be done globally if newman is installed globally, otherwise install without `-g` option
---
## Usage
Specify `-r influxdb` option while running the collection
```bash
newman run <collection-url> -r influxdb \
--reporter-influxdb-server <server-ip> \
--reporter-influxdb-port <server-port> \
--reporter-influxdb-name <database-name> \
--reporter-influxdb-measurement <measurement-name>
```
- By default, reporter consider influxdb version 1.x (i.e 1.7, 1.8)
- In case of InfluxDB version 2, specify version, org and bucket name as well
- `--reporter-influxdb-version 2`
- `--reporter-influxdb-org <org-name>`
- `--reporter-influxdb-name <bucket-name>`
Example:
```
# For InfluxDB version 1.x
newman run https://www.getpostman.com/collections/631643-f695cab7-6878-eb55-7943-ad88e1ccfd65-JsLv -r influxdb \
--reporter-influxdb-server localhost \
--reporter-influxdb-port 8086 \
--reporter-influxdb-name newman_reports \
--reporter-influxdb-measurement api_results
# For InfluxDB version 2.x
newman run https://www.getpostman.com/collections/631643-f695cab7-6878-eb55-7943-ad88e1ccfd65-JsLv -r influxdb \
--reporter-influxdb-server localhost \
--reporter-influxdb-port 8086 \
--reporter-influxdb-org viz \
--reporter-influxdb-version 2 \
--reporter-influxdb-username viz \
--reporter-influxdb-password db123456 \
--reporter-influxdb-name viz \
--reporter-influxdb-measurement api_results
```
### Options:
**Option** | **Remarks**
--- | ---
`--reporter-influxdb-server` | IP Address or Host of InfluxDB
`--reporter-influxdb-port` | Port no. (Usually `8086`)

PROJECT = "newman-reporter-influxdb"
.PHONY: local-install
local-install:
npm uninstall -g ${PROJECT}
npm pack
npm install -g ${PROJECT}-*.tgz

request(error, args) {
const { cursor, item, request } = args;
console.log(`[${this.context.currentItem.index}] Running ${item.name}`);
const data = {
collection_name: this.options.collection.name,
id: this.context.identifier,
request_name: item.name,
url: request.url.toString(),
method: request.method,
status: args.response.status,
code: args.response.code,
response_time: args.response.responseTime,
response_size: args.response.responseSize,
test_status: 'PASS',
assertions: 0,
failed_count: 0,
skipped_count: 0,
failed: [],
skipped: []
};
this.context.currentItem.data = data;
this.context.currentItem.name = item.name;


Step 2: ⌨️ Coding

Modify src/influxdb-reporter.js with contents:
• Add a conditional check to determine if 'args.response' is defined before attempting to access its properties.
• If 'args.response' is undefined, set default values for 'status' and 'code' to indicate a failed request or a network error. For example, 'status' could be set to 'Failed' and 'code' to 0.
• Modify the 'data' object construction within the 'request' method to use the checked and potentially default values for 'status' and 'code'.
• The modified code block should look something like this:
request(error, args) {
  const { cursor, item, request } = args;

  console.log(`[${this.context.currentItem.index}] Running ${item.name}`);

  // Check if response is available, otherwise set default values
  const responseStatus = args.response ? args.response.status : 'Failed';
  const responseCode = args.response ? args.response.code : 0;

  const data = {
    collection_name: this.options.collection.name, 
    id: this.context.identifier,
    request_name: item.name,
    url: request.url.toString(),
    method: request.method,
    status: responseStatus,
    code: responseCode,
    response_time: args.response ? args.response.responseTime : null,
    response_size: args.response ? args.response.responseSize : null,
    test_status: 'PASS',
    assertions: 0,
    failed_count: 0,
    skipped_count: 0,
    failed: [],
    skipped: []
  };

  this.context.currentItem.data = data;
  this.context.currentItem.name = item.name;
}
```<br/>• Note that 'response_time' and 'response_size' are also conditionally accessed, with null as the default value if 'args.response' is undefined.

<pre>--- 
+++ 
@@ -93,10 +93,10 @@
       request_name: item.name,
       url: request.url.toString(),
       method: request.method,
-      status: args.response.status,
-      code: args.response.code,
-      response_time: args.response.responseTime,
-      response_size: args.response.responseSize,
+      status: args.response ? args.response.status : 'Failed',
+      code: args.response ? args.response.code : 0,
+      response_time: args.response ? args.response.responseTime : null,
+      response_size: args.response ? args.response.responseSize : null,
       test_status: 'PASS',
       assertions: 0,
       failed_count: 0,
</pre>
</blockquote>

- [X] Running GitHub Actions for `src/influxdb-reporter.js` ✓  [Edit](https://github.com/vs4vijay/newman-reporter-influxdb/edit/sweep/cannot_read_properties_of_undefined_read_62ab7/src/influxdb-reporter.js#L85-L108)
<blockquote>Check src/influxdb-reporter.js with contents:

Ran GitHub Actions for <a href="https://github.com/vs4vijay/newman-reporter-influxdb/commit/decd6d811579d59eea6062529d9a36bcae53bc47">decd6d811579d59eea6062529d9a36bcae53bc47</a>:



</blockquote>


---
## Step 3: 🔁 Code Review
I have finished reviewing the code for completeness. I did not find errors for  [`sweep/cannot_read_properties_of_undefined_read_62ab7`](https://github.com/vs4vijay/newman-reporter-influxdb/commits/sweep/cannot_read_properties_of_undefined_read_62ab7).



---

<details>
<summary><b>🎉 Latest improvements to Sweep:</b></summary>
<ul>
<li>New <a href="https://progress.sweep.dev">dashboard</a> launched for real-time tracking of Sweep issues, covering all stages from search to coding.</li>
<li>Integration of OpenAI's latest Assistant API for more efficient and reliable code planning and editing, improving speed by 3x.</li>
<li>Use the <a href="https://marketplace.visualstudio.com/items?itemName=GitHub.vscode-pull-request-github">GitHub issues extension</a> for creating Sweep issues directly from your editor.</li>
</ul>
</details>


💡 To recreate the pull request edit the issue title or description. To tweak the pull request, leave a comment on the pull request.<sup>Something wrong? [Let us know](https://discord.gg/sweep).</sup>

*This is an automated message generated by [Sweep AI](https://sweep.dev).*

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sweep Sweep your software chores
Projects
None yet
Development

No branches or pull requests

1 participant