Improve error message for issues to access balena settings

Update balena-settings-storage from 6.0.1 to 7.0.0

Resolves: #1667
Change-type: patch
This commit is contained in:
josecoelho 2020-09-28 22:08:07 +00:00 committed by Jose Coelho
parent 0d3ca63f00
commit 439d8391ee
3 changed files with 35 additions and 16 deletions

View File

@ -20,6 +20,7 @@ import * as os from 'os';
import { TypedError } from 'typed-error';
import { getChalk, stripIndent } from './utils/lazy';
import { getHelp } from './utils/messages';
import { CliSettings } from './utils/bootstrap';
export class ExpectedError extends TypedError {
public code?: string;
@ -104,6 +105,17 @@ function interpret(error: Error): string {
return error.message;
}
function loadDataDirectory(): string {
try {
const settings = new CliSettings();
return settings.get('dataDirectory') as string;
} catch {
return os.platform() === 'win32'
? 'C:\\Users\\<user>\\_balena'
: '$HOME/.balena';
}
}
const messages: {
[key: string]: (error: Error & { path?: string }) => string;
} = {
@ -127,6 +139,23 @@ const messages: {
EACCES: (e) => messages.EPERM(e),
BalenaSettingsPermissionError: () => {
const dataDirectory = loadDataDirectory();
return stripIndent`
Error reading data directory: "${dataDirectory}"
This error usually indicates that the user doesn't have permissions over that directory,
which can happen if balena CLI was executed as the root user.
${
os.platform() === 'win32'
? `Try resetting the ownership by opening a new Command Prompt as administrator and running: \`takeown /f ${dataDirectory} /r\``
: `Try resetting the ownership by running: \`sudo chown -R $(whoami) ${dataDirectory}\``
}
`;
},
ETIMEDOUT: () =>
'Oops something went wrong, please check your connection and try again.',
@ -151,6 +180,7 @@ const messages: {
// related issue https://github.com/balena-io/balena-sdk/issues/1025
// related issue https://github.com/balena-io/balena-cli/issues/2126
const EXPECTED_ERROR_REGEXES = [
/^BalenaSettingsPermissionError/, // balena-settings-storage
/^BalenaAmbiguousApplication/, // balena-sdk
/^BalenaAmbiguousDevice/, // balena-sdk
/^BalenaApplicationNotFound/, // balena-sdk

19
npm-shrinkwrap.json generated
View File

@ -2534,18 +2534,6 @@
"balena-settings-storage": "^7.0.0",
"jwt-decode": "^2.2.0",
"tslib": "^2.0.0"
},
"dependencies": {
"balena-settings-storage": {
"version": "7.0.0",
"resolved": "https://registry.npmjs.org/balena-settings-storage/-/balena-settings-storage-7.0.0.tgz",
"integrity": "sha512-gufzVJznyt9e1CvpBuLe2caU5KcEwl1YHCbK5OMz09zXDA2OMAICPXsLlViK+KiuZwZrBx3tyU2FZjAzRZFgwQ==",
"requires": {
"@types/node": "^10.17.26",
"balena-errors": "^4.7.1",
"tslib": "^2.0.0"
}
}
}
},
"balena-config-json": {
@ -2793,11 +2781,12 @@
}
},
"balena-settings-storage": {
"version": "6.0.1",
"resolved": "https://registry.npmjs.org/balena-settings-storage/-/balena-settings-storage-6.0.1.tgz",
"integrity": "sha512-jdDoKzbJXlF696EZSbwD6lZ1dMe98aUtx7btFE4j4PRCSeh2BWx5P5VLGh9Bk3sH2FUcqYg0iw/wdKvkcv44oA==",
"version": "7.0.0",
"resolved": "https://registry.npmjs.org/balena-settings-storage/-/balena-settings-storage-7.0.0.tgz",
"integrity": "sha512-gufzVJznyt9e1CvpBuLe2caU5KcEwl1YHCbK5OMz09zXDA2OMAICPXsLlViK+KiuZwZrBx3tyU2FZjAzRZFgwQ==",
"requires": {
"@types/node": "^10.17.26",
"balena-errors": "^4.7.1",
"tslib": "^2.0.0"
}
},

View File

@ -204,7 +204,7 @@
"balena-sdk": "^15.20.0",
"balena-semver": "^2.3.0",
"balena-settings-client": "^4.0.5",
"balena-settings-storage": "^6.0.1",
"balena-settings-storage": "^7.0.0",
"balena-sync": "^11.0.2",
"bluebird": "^3.7.2",
"body-parser": "^1.19.0",