mirror of
https://github.com/balena-io/balena-cli.git
synced 2024-12-22 06:57:48 +00:00
Merge pull request #2050 from josecoelho/1667-permission-validation
Improve error message to access balena settings
This commit is contained in:
commit
9637f75617
@ -20,6 +20,7 @@ import * as os from 'os';
|
|||||||
import { TypedError } from 'typed-error';
|
import { TypedError } from 'typed-error';
|
||||||
import { getChalk, stripIndent } from './utils/lazy';
|
import { getChalk, stripIndent } from './utils/lazy';
|
||||||
import { getHelp } from './utils/messages';
|
import { getHelp } from './utils/messages';
|
||||||
|
import { CliSettings } from './utils/bootstrap';
|
||||||
|
|
||||||
export class ExpectedError extends TypedError {
|
export class ExpectedError extends TypedError {
|
||||||
public code?: string;
|
public code?: string;
|
||||||
@ -104,6 +105,17 @@ function interpret(error: Error): string {
|
|||||||
return error.message;
|
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: {
|
const messages: {
|
||||||
[key: string]: (error: Error & { path?: string }) => string;
|
[key: string]: (error: Error & { path?: string }) => string;
|
||||||
} = {
|
} = {
|
||||||
@ -127,6 +139,23 @@ const messages: {
|
|||||||
|
|
||||||
EACCES: (e) => messages.EPERM(e),
|
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: () =>
|
ETIMEDOUT: () =>
|
||||||
'Oops something went wrong, please check your connection and try again.',
|
'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-sdk/issues/1025
|
||||||
// related issue https://github.com/balena-io/balena-cli/issues/2126
|
// related issue https://github.com/balena-io/balena-cli/issues/2126
|
||||||
const EXPECTED_ERROR_REGEXES = [
|
const EXPECTED_ERROR_REGEXES = [
|
||||||
|
/^BalenaSettingsPermissionError/, // balena-settings-storage
|
||||||
/^BalenaAmbiguousApplication/, // balena-sdk
|
/^BalenaAmbiguousApplication/, // balena-sdk
|
||||||
/^BalenaAmbiguousDevice/, // balena-sdk
|
/^BalenaAmbiguousDevice/, // balena-sdk
|
||||||
/^BalenaApplicationNotFound/, // balena-sdk
|
/^BalenaApplicationNotFound/, // balena-sdk
|
||||||
|
19
npm-shrinkwrap.json
generated
19
npm-shrinkwrap.json
generated
@ -2534,18 +2534,6 @@
|
|||||||
"balena-settings-storage": "^7.0.0",
|
"balena-settings-storage": "^7.0.0",
|
||||||
"jwt-decode": "^2.2.0",
|
"jwt-decode": "^2.2.0",
|
||||||
"tslib": "^2.0.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": {
|
"balena-config-json": {
|
||||||
@ -2793,11 +2781,12 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"balena-settings-storage": {
|
"balena-settings-storage": {
|
||||||
"version": "6.0.1",
|
"version": "7.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/balena-settings-storage/-/balena-settings-storage-6.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/balena-settings-storage/-/balena-settings-storage-7.0.0.tgz",
|
||||||
"integrity": "sha512-jdDoKzbJXlF696EZSbwD6lZ1dMe98aUtx7btFE4j4PRCSeh2BWx5P5VLGh9Bk3sH2FUcqYg0iw/wdKvkcv44oA==",
|
"integrity": "sha512-gufzVJznyt9e1CvpBuLe2caU5KcEwl1YHCbK5OMz09zXDA2OMAICPXsLlViK+KiuZwZrBx3tyU2FZjAzRZFgwQ==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"@types/node": "^10.17.26",
|
"@types/node": "^10.17.26",
|
||||||
|
"balena-errors": "^4.7.1",
|
||||||
"tslib": "^2.0.0"
|
"tslib": "^2.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -204,7 +204,7 @@
|
|||||||
"balena-sdk": "^15.20.0",
|
"balena-sdk": "^15.20.0",
|
||||||
"balena-semver": "^2.3.0",
|
"balena-semver": "^2.3.0",
|
||||||
"balena-settings-client": "^4.0.5",
|
"balena-settings-client": "^4.0.5",
|
||||||
"balena-settings-storage": "^6.0.1",
|
"balena-settings-storage": "^7.0.0",
|
||||||
"balena-sync": "^11.0.2",
|
"balena-sync": "^11.0.2",
|
||||||
"bluebird": "^3.7.2",
|
"bluebird": "^3.7.2",
|
||||||
"body-parser": "^1.19.0",
|
"body-parser": "^1.19.0",
|
||||||
|
Loading…
Reference in New Issue
Block a user