Skip to content

FIX-MISSING-FILE: Cannot read property 'ns' of null - when missing proto/json files #227

@cblair

Description

@cblair

Problem

When trying to load proto files, if the path is not found, grpc dies in a non-obvious way:

TypeError: Cannot read property 'ns' of null
      at Object.load (node_modules/grpc/index.js:146:28)
      at loadRpcService (node_modules/@communityco/platform-helpers/lib/service/utils/grpc.js:42:22)
      at createRpcClient (node_modules/@communityco/platform-helpers/lib/service/utils/grpc.js:60:19)
      at createClient (node_modules/@communityco/platform-helpers/lib/service/index.js:55:22)
      at Context.before (test/profiles.component.test.js:58:14)

Synopsis

This is due to some fault intolerant code when making an internal builder object:

return loadObject(builder.ns, options);

try {
    switch(format) {
      case 'proto':
      builder = ProtoBuf.loadProtoFile(filename);
      break;
      case 'json':
      builder = ProtoBuf.loadJsonFile(filename);
      break;
      default:
      throw new Error('Unrecognized format "' + format + '"');
    }
  } finally {
    ProtoBuf.convertFieldsToCamelCase = convertFieldsToCamelCaseOriginal;
  }
  return loadObject(builder.ns, options);

Expected Behavior

In the case in which a file cannot be found, throw an exception indicating so.

Simple fix, PR WIP.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions