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 property 'x-stream-error' of undefined #21229

Closed
Nanofortress opened this issue Sep 20, 2018 · 5 comments
Closed

Cannot read property 'x-stream-error' of undefined #21229

Nanofortress opened this issue Sep 20, 2018 · 5 comments
Labels
Ran Commands One of our bots successfully processed a command. Resolution: Locked This issue was locked by the bot.

Comments

@Nanofortress
Copy link

Nanofortress commented Sep 20, 2018

Environment

React Native Environment Info:
System:
OS: macOS High Sierra 10.13.6
CPU: x64 Intel(R) Core(TM) i5-4308U CPU @ 2.80GHz
Memory: 30.14 MB / 8.00 GB
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 10.8.0 - /usr/local/bin/node
Yarn: 1.9.4 - /usr/local/bin/yarn
npm: 6.4.0 - /usr/local/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
SDKs:
iOS SDK:
Platforms: iOS 11.4, macOS 10.13, tvOS 11.4, watchOS 4.3
Android SDK:
Build Tools: 23.0.1, 25.0.0, 26.0.1, 26.0.3, 27.0.3, 28.0.2
API Levels: 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28
IDEs:
Android Studio: 3.1 AI-173.4907809
Xcode: 9.4.1/9F2000 - /usr/bin/xcodebuild
npmPackages:
react: 16.4.1 => 16.4.1
react-native: 0.56.0 => 0.56.0
npmGlobalPackages:
create-react-native-app: 1.0.0
react-native-cli: 2.0.1

I am having this problem when trying to use ipfs-api module on React Native. I am using the ipfs-api version 24.0.1 imported to React Native with rn-nodeify version 10.0.0 with the following steps:

npm i --save rn-nodeify
npm i --save ipfs-api

Then uncomment require('crypto') in shim.js at the root of React Native project.
Then go to this file:

vi ./node_modules/isomorphic-fetch/fetch-npm-browserify.js

and add

var self = this;

before module.exports line in the file.
Finally run:

./node_modules/.bin/rn-nodeify --hack --install
react-native link

Code

I have the following code in my project following the example for ipfs-api:

const ipfsAPI = require("ipfs-api");
...
ipfs = ipfsAPI("127.0.0.1", "5001", { protocol: "http" });
...
ipfs.files.write(       // Error here
      "/aaa.txt",
      buffer,
      {
        create: true,
        parents: true
      },
      err => {
        console.log(err);
      }
    );

Error

When I tried running the code above in my project I get the following error:

e5

And in the debugger I see the following:

e4

The problem is that there is no res.trailers element for the res variable inside the onRes function.
This function is located at /node_modules/ipfs-api/src/utils/send-request.js


Any thoughts is welcome, thanks for your time!

@react-native-bot
Copy link
Collaborator

Can you run react-native info and edit your issue to include these results under the Environment section?

If you believe this information is irrelevant to the reported issue, you may write [skip envinfo] under Environment to let us know.

@Nanofortress
Copy link
Author

A very straight forward fix is to simply comment out the part where its getting the res.trailers['x-stream-error']. But I think there should be a better way to do it. If anyone knows a better solution please let me know, thanks!

// Return a stream of JSON objects
    if (chunkedObjects && isJson) {
      const outputStream = ndjson.parse()
      pump(res, outputStream)
      res.on('end', () => {
        // let err = res.trailers['x-stream-error']
        // if (err) {
        //   // Not all errors are JSON
        //   try {
        //     err = JSON.parse(err)
        //   } catch (e) {
        //     err = { Message: err }
        //   }
        //   outputStream.emit('error', new Error(err.Message))
        // }
      })
      return cb(null, outputStream)
    }

@react-native-bot
Copy link
Collaborator

It looks like you are using an older version of React Native. Please update to the latest release, v0.57 and verify if the issue still exists.

The ":rewind:Old Version" label will be removed automatically once you edit your original post with the results of running react-native info on a project using the latest release.

@Nanofortress
Copy link
Author

It seems like the response from ipfs is corrupted or malformed. The picture below shows the Wireshark tracking the packet sent from ipfs to my app and the data is malformed.

e6

This shows that in the packet inside trailer the x-stream-error is specified so there is indeed a x-stream-error to read from. So most-likely the ipfs node running is sending a bad response.

The ipfs version I am running is version 0.4.17.

Again please leave a comment if you have any idea why this happening, thanks in advance!

@react-native-bot
Copy link
Collaborator

I am closing this issue because it does not appear to have been verified on the latest release, and there has been no followup in a while.

If you found this thread after encountering the same issue in the latest release, please feel free to create a new issue with up-to-date information by clicking here.

@react-native-bot react-native-bot added the Ran Commands One of our bots successfully processed a command. label Oct 5, 2018
@facebook facebook locked as resolved and limited conversation to collaborators Oct 5, 2019
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Oct 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Ran Commands One of our bots successfully processed a command. Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

2 participants