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

TypeError: Cannot read property 'toString' of undefined #4

Open
shc261392 opened this issue Apr 23, 2020 · 4 comments
Open

TypeError: Cannot read property 'toString' of undefined #4

shc261392 opened this issue Apr 23, 2020 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@shc261392
Copy link

Issue description

I encountered this error message when calling the store API:

{"message":"TypeError: Cannot read property 'toString' of undefined\n    at Object.proposeStorageDeal (/Users/james/numbers/starling-api/node_modules/filecoin-api-client/src/  cmd/client/propose-storage-deal.js:10:18)\n    at proposeDeal (/Users/james/numbers/starling-api/lib/apis/store/controller/store.js:115:51)\n    at ProposeDeals.Promise.all.   importedFiles.map.file (/Users/james/numbers/starling-api/lib/apis/store/controller/store.js:157:16)\n    at Array.map (<anonymous>)\n    at ProposeDeals (/Users/james/   numbers/starling-api/lib/apis/store/controller/store.js:154:21)\n    at store (/Users/james/numbers/starling-api/lib/apis/store/index.js:29:11)\n    at process._tickCallback   (internal/process/next_tick.js:68:7)","level":"error"}

After adding some debug console to the starling-api, I've found that the cid and name parameter passed to this function is always undefined if only 1 file is going to be stored.

It turns out that in this line

const FILE = filesCount === 1 ? file : file[0];

return proposeDeal(db, FILE, miners, i);

The FILE object is actually an array if there's only one file (the filesCount here is 1)

[ { cid: 'Qmf2WJRKky6WNnsmUs9pnQ39zufebJ6xusHYfbPS99yXjX',
fileSize: 13409,
name: 'xmp.txt' } ]

but the function proposeDeal should accept the file object instead of an array of the file objects

Steps to reproduce

The complete Python 3 code to invoke the API:

#!/usr/bin/env python3
 import json

 import requests

 base_url = 'http://localhost:3000'

 base_headers = {
     'Accept': 'application/vnd.starling+json; version=1.0',
 }

 def store():
     with open('xmp.json', 'r') as f:
         data = json.load(f)

     res = requests.post(
         url=base_url + '/api/store',
         headers=base_headers,
         data=data,
     )
     try:
         res.raise_for_status()
     except Exception as e:
         print(e.response)
     return res.text

 r = store()
 print(r)

xmp.json:

{
     "dataPath": "/Users/james/numbers/starling-test/xmp/"
 }

where the xmp/ folder contains only 1 file, an xmp.txt file

Environment

starling-api commit hash: d6cb6b4
filecoin version: v0.5.8

@finoradin finoradin added the bug Something isn't working label Apr 23, 2020
@mishmosh
Copy link

mishmosh commented May 1, 2020

@finoradin Just to confirm, this bug with ProposeDeal is at the starling-api level and not go-filecoin? (cc @ognots)

@finoradin
Copy link
Contributor

@finoradin Just to confirm, this bug with ProposeDeal is at the starling-api level and not go-filecoin? (cc @ognots)

I haven't tried to reproduce it, but based on how it has been reporting, yes that is my understanding.

@bafu
Copy link

bafu commented May 20, 2020

@mishmosh @finoradin Thanks for the comments. According to current status, do you have any suggestion about using the store API?

@mishmosh
Copy link

This issue is expected to be fixed early next week, with the rewrite of the store command as part of the migration to lotus that @alexandrumatei36 is working on. I will update here once that's merged in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants