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

CLI prints "null" and exits with error code 1 #1333

Closed
pdcastro opened this issue Jul 1, 2019 · 10 comments
Closed

CLI prints "null" and exits with error code 1 #1333

pdcastro opened this issue Jul 1, 2019 · 10 comments
Assignees
Labels
cause:sentry Issues that are related to sentry / raven client library behaviour. type:bug

Comments

@pdcastro
Copy link
Contributor

pdcastro commented Jul 1, 2019

This error is rare but can happen with any balena CLI command, any platform (Windows, Mac, Linux) and any installation type (npm dev, npm production, standalone zip, executable installer). The most recent example was issue #1331, and it is closely related to issue #1193.

It happens because of an issue / bug in the Sentry library, which is supposed to intercept errors and report them to Balena via the sentry.io platform. It seems that the Sentry library (at least the old version being used) cannot cope with certain types of errors, and then itself fails and "masks" the underlying error, resulting in "null" being printed to the console:

$ balena login
null

That's a rather frustrating error, difficult to debug. A workaround (to reveal the underlying error) is to sidestep the Sentry library by commenting out (//) the setupRaven() line in the build/app-common.js file, so that it looks as follows:

    // setupRaven();

If the CLI was installed with the executable (native) installers, the file is located at:

OS File
Windows C:\Program Files\balena-cli\client\build\app-common.js
macOS /usr/local/lib/balena-cli/build/app-common.js

With the "npm installation", it depends on where Node.js was installed and whether nvm was used, but typical locations are:

OS File
Linux /usr/local/lib/node_modules/balena-cli/build/app-common.js
nvm ~/.nvm/versions/node/vX.Y.Z/lib/node_modules/balena-cli/build/app-common.js

This workaround is not possible in the standalone zip packages, as the source code is bundled in the executable binary.

The first step towards a proper fix is probably to update the Sentry library being used by the CLI (#1523). Unfortunately it's not just a matter of updating a dependency version, because Sentry did a re-writing of the public API.

@pdcastro
Copy link
Contributor Author

pdcastro commented Jul 1, 2019

Draft pull request: #1295

@balena-ci
Copy link
Contributor

[pdcastro] This issue has attached support thread https://jel.ly.fish/#/support-thread~17dc1bb6-a481-4b68-aa64-e961ffd4b794

@pdcastro
Copy link
Contributor Author

"hello" support conversation: https://app.frontapp.com/open/cnv_1yv269v

@pdcastro
Copy link
Contributor Author

pdcastro commented Jul 10, 2019

On macOS, in order to edit the /usr/local/lib/balena-cli/build/app-common.js file, you can use the nano command-line text editor. Open a terminal prompt and run:

$ sudo nano /usr/local/lib/balena-cli/build/app-common.js
Password:

It will prompt you for the computer login password because the file is owned by the root user. The window will look something like the following screenshot. Use the arrow keys to navigate towards the end of the file, and type // before setupRaven(); (in the globalInit() function) as shown in the screenshot. Then type Ctrl-O to save the file, and Ctrl-X to exit.

nano

@alsmith
Copy link

alsmith commented Jul 10, 2019

I ran into this problem and after commenting out the setupRaven() call, it emerged that the problem was due to $HOME/.balena being owned by root. It was empty anyway so I got rid of it, uncommented setupRaven() again and everything works now.

@HAKASHUN
Copy link

Though I am using an older version of cli (resin-cli@8.1.0), I encountered the same error.

I fixed part of the require('any-promise/register/bluebird') code because an Error is happened in any-promise/loader.js.

# Assign bluebird as the global promise library
# stream-to-promise will produce native promises if not
# for this module, which could wreak havoc in this
# bluebird-only codebase.
require('any-promise/register/bluebird')

// Before
require('any-promise/register/bluebird')

// After
require('any-promise')

The same fixes in app-common.ts may improve it 🤔 .

MyEnvironment
OS Mac
Node 8.9.4
Cli resin-cli@8.1.0

@jacobrosenthal
Copy link

Mine was

Error: Setting not found: apiUrl

Then when digging around I found an empty ~/.balenarc.yml file which when deleted got me working again

@srlowe srlowe added type:bug cause:sentry Issues that are related to sentry / raven client library behaviour. labels Oct 31, 2019
@pdcastro pdcastro added this to the Sorted Backlog milestone Nov 21, 2019
@balena-ci
Copy link
Contributor

[pdcastro] This issue has attached support thread https://jel.ly.fish/#/49b14f58-7f34-40c4-95c2-f0596a1377ab

@balena-ci
Copy link
Contributor

[pdcastro] This issue has attached support thread https://jel.ly.fish/#/55a77735-863d-4e2f-90cc-034c92e05c25

@pdcastro pdcastro self-assigned this Mar 4, 2020
pdcastro added a commit that referenced this issue Mar 5, 2020
…y SDK)

Resolves: #1523
Connects-to: #1333
Connects-to: #1193
Change-type: patch
pdcastro added a commit that referenced this issue Mar 5, 2020
…y SDK)

Resolves: #1523
Connects-to: #1333
Connects-to: #1193
Change-type: patch
pdcastro added a commit that referenced this issue Mar 5, 2020
…y SDK)

Resolves: #1523
Connects-to: #1333
Connects-to: #1193
Change-type: patch
pdcastro added a commit that referenced this issue Mar 6, 2020
…y SDK)

Resolves: #1523
Connects-to: #1333
Connects-to: #1193
Change-type: patch
pdcastro added a commit that referenced this issue Mar 9, 2020
…y SDK)

Resolves: #1523
Connects-to: #1333
Connects-to: #1193
Change-type: patch
@pdcastro
Copy link
Contributor Author

This issue should be fixed in CLI release 11.28.14 (releases). If you still come across this issue ("prints null and exits") with CLI v11.28.14 or later, please leave a comment and we can reopen this issue (or you are also welcome to create a new issue).

If you needed/wanted to get around the issue by commenting out the setupRaven() line (as shown in a screenshot above) with newer CLI releases (11.28.14 and later), please note that that line was replaced with await setupSentry() (https://github.com/balena-io/balena-cli/blob/v11.28.14/lib/app-common.ts#L245), so the commented out line in newer releases would look like:

export async function globalInit() {
	// await setupSentry();
	...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cause:sentry Issues that are related to sentry / raven client library behaviour. type:bug
Projects
None yet
Development

No branches or pull requests

6 participants