Skip to content

Scoping error in packages/common/src/util.js #1654

Closed

Description

@abawany

When Google Storage is used to access a file that does not exist, the following uncaught exception is generated by the package:

error:  ApiError: Not Found
    at new util.ApiError (/tmp/node_modules/google-cloud/node_modules/@google-cloud/common/src/util.js:107:10)
    at Object.parseHttpRespMessage (/tmp/node_modules/google-cloud/node_modules/@google-cloud/common/src/util.js:149:33)
    at Object.handleResp (/tmp/node_modules/google-cloud/node_modules/@google-cloud/common/src/util.js:124:18)
    at .<anonymous> (/tmp/node_modules/google-cloud/node_modules/@google-cloud/storage/src/file.js:632:21)
    at emitOne (events.js:96:13)
    at emit (events.js:188:7)
    at emitOne (events.js:96:13)
    at DestroyableTransform.emit (events.js:188:7)
    at emitOne (events.js:96:13)
    at Request.emit (events.js:188:7)

Going to line 107 of the offending file shows this:

106: util.ApiError = function(errorBody) {
107:  return new ApiError(errorBody);
108: };

(EDIT: alleged remedy was not a solution either). ApiError is defined above this code as var ApiError = ....

Environment details

  • OS: OSX
  • Node.js version: 6.2.1
  • npm version: 3.9.3
  • google-cloud-node version: 0.41.2

Steps to reproduce

  1. require google-cloud
  2. use the storage module to access a non-existent file in a GS bucket

Making sure to follow these steps will guarantee the quickest resolution possible.

Thanks!

Activity

  1. added
    type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.
    api: storageIssues related to the Cloud Storage API.
    on Sep 30, 2016
  2. abawany commented on Sep 30, 2016

    @abawany
    Author

    On capturing a stack trace at the offending line, it appears that the function above is invoked thrice. The first invocation works but the next two fail. The code that invokes the above function is as follows (line 149 of the same file):

    function parseHttpRespMessage(httpRespMessage) {
      var parsedHttpRespMessage = {
        resp: httpRespMessage
      };
    
      if (httpRespMessage.statusCode < 200 || httpRespMessage.statusCode > 299) {
        // Unknown error. Format according to ApiError standard.
        parsedHttpRespMessage.err = new util.ApiError({ // this is line 149
          errors: [],
          code: httpRespMessage.statusCode,
          message: httpRespMessage.statusMessage,
          response: httpRespMessage
        });
      }
    
      return parsedHttpRespMessage;
    }
    
  3. stephenplusplus commented on Sep 30, 2016

    @stephenplusplus
    Contributor

    Can you show the code you're using that access our library?

  4. abawany commented on Sep 30, 2016

    @abawany
    Author

    Sure. I was previously using [email protected] and hadn't noticed these issues. Moving to google-cloud (starting with 0.40.0 and now at 0.41.2) shows these issues.

    var gc = require('google-cloud') ({ projectId: 'something' });
    var gsInst = gc.storage({ projectId: 'something' });
    var bucket = gsInst.bucket('bucket');
    var destFile = bucket.file(fromFile);
    var strm = destFile.createReadStream({validation: 'crc32c'});
    strm
      .on('error', function(e) { 
        log.inst.error({e: e.stack});
        return cb(e); 
      })
      .pipe(res)
      .on('response', function(r) { log.inst.debug({r: r}); })
      .on('end', function() { 
        log.inst.debug({end: true}); 
        return res.send(200); 
      }
    );
    
  5. stephenplusplus commented on Sep 30, 2016

    @stephenplusplus
    Contributor

    I haven't been able to reproduce with the following code using @google-cloud/storage@0.2.0 (included in google-cloud > 41.0):

    {
      "name": "@google-cloud/gissue-1654",
      "version": "1.0.0",
      "description": "",
      "main": "index.js",
      "scripts": {
        "test": "echo \"Error: no test specified\" && exit 1"
      },
      "keywords": [],
      "author": "",
      "license": "ISC",
      "dependencies": {
        "@google-cloud/storage": "^0.2.0"
      }
    }
    
    var storage = require('@google-cloud/storage')({ authInfo })
    var stream = require('stream')
    
    var file = storage.bucket('stephen-has-a-new-bucket').file('non-existent-file')
    
    file.createReadStream({ validation: 'crc32c' })
      .on('error', function(e) {
        console.log('error', e)
      })
      .on('data', function() {})

    Would you mind trying it in this format, which doesn't have other dependencies?

  6. abawany commented on Sep 30, 2016

    @abawany
    Author

    The code is behaving as expected. The issue that caused the uce was due to passing the error object returned by this call to gcloud logging instead of error.stack. Here was the uce for reference - I will close this issue.

    { t: 'object',
      x: 
       TypeError: obj.hasOwnProperty is not a function
           at Function.GrpcService.objToStruct_ (/tmp/node_modules/google-cloud/node_modules/@google-cloud/common/src/grpc-service.js:669:13)
           at Function.GrpcService.encodeValue_ (/tmp/node_modules/google-cloud/node_modules/@google-cloud/common/src/grpc-service.js:506:32)
           at Function.GrpcService.objToStruct_ (/tmp/node_modules/google-cloud/node_modules/@google-cloud/common/src/grpc-service.js:676:50)
           at Function.GrpcService.encodeValue_ (/tmp/node_modules/google-cloud/node_modules/@google-cloud/common/src/grpc-service.js:506:32)
           at Function.GrpcService.objToStruct_ (/tmp/node_modules/google-cloud/node_modules/@google-cloud/common/src/grpc-service.js:676:50)
           at Function.GrpcService.encodeValue_ (/tmp/node_modules/google-cloud/node_modules/@google-cloud/common/src/grpc-service.js:506:32)
           at Function.GrpcService.objToStruct_ (/tmp/node_modules/google-cloud/node_modules/@google-cloud/common/src/grpc-service.js:676:50)
           at Function.GrpcService.encodeValue_ (/tmp/node_modules/google-cloud/node_modules/@google-cloud/common/src/grpc-service.js:506:32)
           at Function.GrpcService.objToStruct_ (/tmp/node_modules/google-cloud/node_modules/@google-cloud/common/src/grpc-service.js:676:50)
           at Function.GrpcService.encodeValue_ (/tmp/node_modules/google-cloud/node_modules/@google-cloud/common/src/grpc-service.js:506:32),
      e: '{}' }
    
  7. stephenplusplus commented on Sep 30, 2016

    @stephenplusplus
    Contributor

    Phew, glad it worked out!

  8. abawany commented on Feb 1, 2021

    @abawany
    Author

    @JustinBeckwith and @stephenplusplus not sure why this 4 year old bug was re-assigned to me but it is closed anyways so no harm no foul, I guess ?

  9. added a commit that references this issue on Mar 11, 2026
  10. added a commit that references this issue on Mar 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

api: storageIssues related to the Cloud Storage API.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions