readmeio/api

Cannot console.log the api object

Closed this issue · 2 comments

If you try and do the following:

const { join } = require('path');
const readme = require('api')(join(__dirname, '../openapi.json'));

console.log(readme);

It prints out a ton of errors:

Promise { <pending> }
(node:21989) UnhandledPromiseRejectionWarning: TypeError: Cannot convert a Symbol value to a string
    at Proxy.<anonymous> (/Users/domh/Sites/readmeio/readme/node_modules/api/src/index.js:111:43)
    at process._tickCallback (internal/process/next_tick.js:68:7)
    at Function.Module.runMain (internal/modules/cjs/loader.js:832:11)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)
(node:21989) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:21989) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

This may not actually be possible for us to do because of the Proxy, but I'd love to be able to inspect what methods are available on the api. Maybe this is something that typescript types would help with (since I'm using vscode atm).

The error appears to be coming from:

throw new Error(`Sorry, \`${method}\` does not appear to be a valid operation on this API.`);

If I console.log(method) there it returns Symbol(nodejs.util.inspect.custom).

This doesn't look like it's going to be possible with the library in its current form. We can detect if sdk is passed into console.log by checking if String(method) is equal to Symbol(nodejs.util.inspect.custom), but that's about as far as we can go because the bulk of the get method in our Proxy is an async function and that won't work with console logging.

Closing this out because it's not going to be possible with the way the Symbol stuff works. You can console.log out an SDK instance with the new codegen stuff though