Closed a-musing-moose closed 8 years ago
Note I get the same error when trying to run:
resin help
and resin quickstart
Hi @a-musing-moose, thanks for reaching out!
That's indeed very weird! Can you try re-running any of the commands that trigger the error with DEBUG=true
?
DEBUG=true resin login
Exposing that environment variable will allow you to see the stack trace of the error, hopefully giving more information about why this is happening.
Thanks @jviotti
mossj@pretty-on-the-inside:~$ DEBUG=true resin login
ResinRequestError: Request error: Unauthorized
at /usr/lib/node_modules/resin-cli/node_modules/resin-sdk/node_modules/resin-request/build/request.js:123:13
at tryCatcher (/usr/lib/node_modules/resin-cli/node_modules/bluebird/js/main/util.js:26:23)
at Promise._settlePromiseFromHandler (/usr/lib/node_modules/resin-cli/node_modules/bluebird/js/main/promise.js:505:31)
at Promise._settlePromiseAt (/usr/lib/node_modules/resin-cli/node_modules/bluebird/js/main/promise.js:581:18)
at Promise._settlePromises (/usr/lib/node_modules/resin-cli/node_modules/bluebird/js/main/promise.js:697:14)
at Async._drainQueue (/usr/lib/node_modules/resin-cli/node_modules/bluebird/js/main/async.js:123:16)
at Async._drainQueues (/usr/lib/node_modules/resin-cli/node_modules/bluebird/js/main/async.js:133:10)
at Immediate.Async.drainQueues [as _onImmediate] (/usr/lib/node_modules/resin-cli/node_modules/bluebird/js/main/async.js:15:14)
at processImmediate [as _immediateCallback] (timers.js:383:17)
If you need help, don't hesitate in contacting us at:
GitHub: https://github.com/resin-io/resin-cli/issues/new
Gitter: https://gitter.im/resin-io/chat
@a-musing-moose Thanks for the quick response.
Can you try editing this file: /usr/lib/node_modules/resin-cli/node_modules/resin-sdk/node_modules/resin-request/build/request.js
?
According to the stack trace the error happens in line 123, which corresponds to the following snippet:
if (utils.isErrorCode(response.statusCode)) {
responseError = utils.getErrorMessageFromResponse(response);
throw new errors.ResinRequestError(responseError, response.statusCode);
}
Can you try logging the options
variable? So the snippet looks like this after the edition:
if (utils.isErrorCode(response.statusCode)) {
console.log(options);
responseError = utils.getErrorMessageFromResponse(response);
throw new errors.ResinRequestError(responseError, response.statusCode);
}
And run any of the commands again?
Logging that object will allow us to see what is the HTTP causing the error. BTW, I'm working in a pull request to show this information when DEBUG=true
automatically to better debug these kinds of issues in the future.
I've submitted a PR to resin-request
for showing debug information: https://github.com/resin-io/resin-request/pull/52
@a-musing-moose I published a new version of resin-request
with support for DEBUG=true
to NPM. In case you didn't perform the manual edition yet, you can getaway with it by updating the Resin CLI.
Since the new resin-request
version is a patch increment, the Resin CLI will get the update automatically. Sadly, npm update -g resin-cli
doesn't seem to be enough, so I recommend re-installing from scratch:
$ sudo npm uninstall -g resin-cli
$ sudo npm install -g resin-cli
After that, you should be able to pass DEBUG=true
to see detailed information about failed HTTP requests.
Right - I think I know what is going on now. When I ran the modified version I could see that the options contained a JWT. Which I thought odd as I haven't been able to log in.
So I went digging. Turns out that the token was stored in ~/.resin/token
. Where it came from is anybodies guess.
I deleted the token and was able to get things up and running. So thank you for your help.
It would also be nice if certain commands (like help and login) didn't bomb out if an invalid token is found?
And just a little heads up. /lib/actions/wizard.coffee
contains a hard coded path to the .resin
folder that probably won't work for some of us ;-)
I'm not all that familiar with coffee script or the correct way to determine this path.
can confirm @a-musing-moose fix - i was able to get myself out of the same issue by deleting ~/.resin/token
@a-musing-moose @curcuz Thanks for the investigation, but I'm still struggling to reproduce this here.
~/.resin/token
successfully throws "Malformed token".help
or login
don't make any authenticated request. In fact the only HTTP request being made for those commands is GET https://api.resin.io/config
, which doesn't require authentication.@curcuz Are you running GNU/Linux as well? What NodeJS version are you running?
I also can't think of a reason why ~/.resin/token
gets created automatically. The CLI "touches" the directory if it doesn't exist at startup, but doesn't put anything inside.
@a-musing-moose Thanks for the heads up for the hardcoded path. Looks like something that was used for debugging at some point and got accidentally committed!
@jviotti on osx Yosemite
(deleting ~/.resin/token
fixed it)
Projects > DEBUG=true resin login
{ url: 'https://api.resin.io/whoami',
refreshToken: false,
timeout: 30000,
method: 'GET',
json: true,
strictSSL: true,
gzip: true,
headers: { Authorization: 'Bearer eyJ0eXAiOiJKV1QiLCJhbG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/versions/node/v5.7.0/lib/node_modules/resin-cli/node_modules/resin-sdk/node_modules/resin-request/build/request.js:126:13
at tryCatcher (/Users/daniel/.nvm/versions/node/v5.7.0/lib/node_modules/resin-cli/node_modules/resin-sdk/node_modules/resin-request/node_modules/bluebird/js/main/util.js:26:23)
at Promise._settlePromiseFromHandler (/Users/daniel/.nvm/versions/node/v5.7.0/lib/node_modules/resin-cli/node_modules/resin-sdk/node_modules/resin-request/node_modules/bluebird/js/main/promise.js:505:31)
at Promise._settlePromiseAt (/Users/daniel/.nvm/versions/node/v5.7.0/lib/node_modules/resin-cli/node_modules/resin-sdk/node_modules/resin-request/node_modules/bluebird/js/main/promise.js:581:18)
at Promise._settlePromises (/Users/daniel/.nvm/versions/node/v5.7.0/lib/node_modules/resin-cli/node_modules/resin-sdk/node_modules/resin-request/node_modules/bluebird/js/main/promise.js:697:14)
at Async._drainQueue (/Users/daniel/.nvm/versions/node/v5.7.0/lib/node_modules/resin-cli/node_modules/resin-sdk/node_modules/resin-request/node_modules/bluebird/js/main/async.js:123:16)
at Async._drainQueues (/Users/daniel/.nvm/versions/node/v5.7.0/lib/node_modules/resin-cli/node_modules/resin-sdk/node_modules/resin-request/node_modules/bluebird/js/main/async.js:133:10)
at Immediate.Async.drainQueues [as _onImmediate] (/Users/daniel/.nvm/versions/node/v5.7.0/lib/node_modules/resin-cli/node_modules/resin-sdk/node_modules/resin-request/node_modules/bluebird/js/main/async.js:15:14)
at processImmediate [as _immediateCallback] (timers.js:383:17)
If you need help, don't hesitate in contacting us at:
GitHub: https://github.com/resin-io/resin-cli/issues/new
Gitter: https://gitter.im/resin-io/chat
@danielmahon Thanks for the information.
I've investigated this issue, and it happens when the Resin SDK tries to refresh a token that is already expired in order to make the current request.
The fix touches several modules, but will come very soon.
The fix for this issue landed in resin-request, which is a dependency of resin-sdk, which is installed by the CLI. Given its only a patch version increment, re-installing the CLI should get you the fix thanks to semver:
$ npm uninstall -g resin-cli
$ npm install -g resin-cli
BTW, there is another PR coming (https://github.com/resin-io/resin-cli-errors/pull/9) to interpret the new ResinExpiredToken
SDK error to provide a more friendly message.
Hi All,
I am able to install
resin-cli
on my Ubuntu 15.10 box. But I am unable to run any commands. whatever I try I get an "Unauthorized" message.Ubuntu: 15.10 Node JS: v4.3.1 npm: 2.14.2