Add generic error's message

Change-type: patch
Changelog-entry: Add generic error's message
Signed-off-by: Lorenzo Alberto Maria Ambrosi <lorenzothunder.ambrosi@gmail.com>
This commit is contained in:
Lorenzo Alberto Maria Ambrosi 2020-02-20 15:38:10 +01:00
parent 94a0be3b05
commit ac2e973cb0
7 changed files with 76 additions and 203 deletions

View File

@ -16,7 +16,6 @@
import { faFile, faLink } from '@fortawesome/free-solid-svg-icons';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import * as jsonStorageCb from 'electron-json-storage';
import { sourceDestination } from 'etcher-sdk';
import * as _ from 'lodash';
import { GPTPartition, MBRPartition } from 'partitioninfo';
@ -46,35 +45,36 @@ import { colors } from '../../theme';
import { middleEllipsis } from '../../utils/middle-ellipsis';
import { SVGIcon } from '../svg-icon/svg-icon';
const jsonStorage = {
get: (key: string) => {
return new Promise((resolve, reject) => {
jsonStorageCb.get(key, (err, value) => {
if (err) {
reject(err);
throw err;
}
resolve(value);
return value;
});
});
},
set: (key: string, value: object) => {
return new Promise((resolve, reject) => {
jsonStorageCb.set(key, value, err => {
if (err) {
reject(err);
throw err;
}
resolve(value);
return value;
});
});
},
};
const recentUrlImagesKey = 'recentUrlImages';
const getRecentUrlImages = () =>
jsonStorage.get('recentUrlImages') as Promise<string[]>;
function normalizeRecentUrlImages(urls: any[]): string[] {
if (!Array.isArray(urls)) {
urls = [];
}
return _.chain(urls)
.filter(_.isString)
.reject(_.isEmpty)
.uniq()
.takeRight(5)
.value();
}
function getRecentUrlImages(): string[] {
let urls = [];
try {
urls = JSON.parse(localStorage.getItem(recentUrlImagesKey) || '[]');
} catch {
// noop
}
return normalizeRecentUrlImages(urls);
}
function setRecentUrlImages(urls: string[]) {
localStorage.setItem(
recentUrlImagesKey,
JSON.stringify(normalizeRecentUrlImages(urls)),
);
}
const Card = styled(BaseCard)`
hr {
@ -107,32 +107,27 @@ const URLSelector = ({ done }: { done: (imageURL: string) => void }) => {
string[],
(value: React.SetStateAction<string[]>) => void,
] = React.useState([]);
const [loading, setLoading] = React.useState(false);
React.useEffect(() => {
const fetchRecentUrlImages = async () => {
try {
const recentUrlImages: string[] = await getRecentUrlImages();
if (!Array.isArray(recentUrlImages)) {
setRecentImages([]);
} else {
setRecentImages(recentUrlImages);
}
} catch (err) {
console.error(err);
}
const recentUrlImages: string[] = await getRecentUrlImages();
setRecentImages(recentUrlImages);
};
fetchRecentUrlImages();
}, []);
return (
<Modal
primaryButtonProps={{
disabled: loading,
}}
done={async () => {
const sanitizedRecentUrls = _.uniq(
_.reject([...recentImages, imageURL], _.isEmpty),
);
await jsonStorage.set(
'recentUrlImages',
_.takeRight(sanitizedRecentUrls, 5),
);
done(imageURL);
setLoading(true);
const sanitizedRecentUrls = normalizeRecentUrlImages([
...recentImages,
imageURL,
]);
setRecentUrlImages(sanitizedRecentUrls);
await done(imageURL);
}}
>
<label style={{ width: '100%' }}>
@ -228,7 +223,6 @@ export class SourceSelector extends React.Component<
> {
private unsubscribe: () => void;
private afterSelected: SourceSelectorProps['afterSelected'];
private flows: Flow[];
constructor(props: SourceSelectorProps) {
super(props);
@ -245,19 +239,6 @@ export class SourceSelector extends React.Component<
this.onDrop = this.onDrop.bind(this);
this.showSelectedImageDetails = this.showSelectedImageDetails.bind(this);
this.afterSelected = props.afterSelected.bind(this);
this.flows = [
{
onClick: this.openImageSelector,
label: 'Flash from file',
icon: <FontAwesomeIcon icon={faFile} />,
},
{
onClick: this.openURLSelector,
label: 'Flash from URL',
icon: <FontAwesomeIcon icon={faLink} />,
},
];
}
public componentDidMount() {
@ -376,7 +357,7 @@ export class SourceSelector extends React.Component<
}
let source;
if (SourceType.name === sourceDestination.File.name) {
if (SourceType === sourceDestination.File) {
source = new sourceDestination.File({
path: imagePath,
});
@ -545,9 +526,24 @@ export class SourceSelector extends React.Component<
</>
) : (
<StepSelection>
{_.map(this.flows, flow => {
return <FlowSelector key={flow.label} flow={flow} />;
})}
<FlowSelector
key="Flash from file"
flow={{
onClick: this.openImageSelector,
label: 'Flash from file',
icon: <FontAwesomeIcon icon={faFile} />,
}}
/>
;
<FlowSelector
key="Flash from URL"
flow={{
onClick: this.openURLSelector,
label: 'Flash from URL',
icon: <FontAwesomeIcon icon={faLink} />,
}}
/>
;
</StepSelection>
)}
</div>
@ -593,7 +589,7 @@ export class SourceSelector extends React.Component<
{showURLSelector && (
<URLSelector
done={(imagePath: string) => {
done={async (imagePath: string) => {
// Avoid analytics and selection state changes
// if no file was resolved from the dialog.
if (!imagePath) {
@ -609,7 +605,7 @@ export class SourceSelector extends React.Component<
return;
}
this.selectImageByPath({
await this.selectImageByPath({
imagePath,
SourceType: sourceDestination.Http,
});

View File

@ -25,7 +25,7 @@ import * as path from 'path';
import * as packageJSON from '../../../../package.json';
import * as errors from '../../../shared/errors';
import * as permissions from '../../../shared/permissions';
import { SourceOptions } from '../components/source-selector/source-selector.js';
import { SourceOptions } from '../components/source-selector/source-selector';
import * as flashState from '../models/flash-state';
import * as selectionState from '../models/selection-state';
import * as settings from '../models/settings';

View File

@ -164,11 +164,17 @@ const formatSeconds = (totalSeconds: number) => {
return `${minutes}m${seconds}s`;
};
interface FlashProps {
shouldFlashStepBeDisabled: boolean;
goToSuccess: () => void;
source: SourceOptions;
}
export const Flash = ({
shouldFlashStepBeDisabled,
goToSuccess,
source,
}: any) => {
}: FlashProps) => {
const state: any = flashState.getFlashState();
const isFlashing = flashState.isFlashing();
const flashErrorCode = flashState.getLastFlashErrorCode();

View File

@ -97,7 +97,6 @@ async function writeAndValidate(
onProgress: sdk.multiWrite.OnProgressFunction,
onFail: sdk.multiWrite.OnFailFunction,
): Promise<WriteResult> {
console.log('source', source);
let innerSource: sdk.sourceDestination.SourceDestination = await source.getInnerSource();
if (trim && (await innerSource.canRead())) {
innerSource = new sdk.sourceDestination.ConfiguredSource({

View File

@ -131,8 +131,8 @@ export const error = {
].join(' ');
},
genericFlashError: () => {
return 'Something went wrong. If it is a compressed image, please check that the archive is not corrupted.';
genericFlashError: (err: Error) => {
return `Something went wrong. If it is a compressed image, please check that the archive is not corrupted.\n${err.message}`;
},
validation: () => {

132
npm-shrinkwrap.json generated
View File

@ -497,98 +497,6 @@
"@types/domhandler": "*"
}
},
"@types/electron-json-storage": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/@types/electron-json-storage/-/electron-json-storage-4.0.0.tgz",
"integrity": "sha512-b1+VXOjCPENmXhV0q41NCsJIFwpIjPfuJk++h53O4dQhb2RBZYEMTuAnu/UC+0+PhvmysT1f5WNt8RHM3vGevA==",
"dev": true,
"requires": {
"electron": "^1.7.5"
},
"dependencies": {
"@types/node": {
"version": "8.10.59",
"resolved": "https://registry.npmjs.org/@types/node/-/node-8.10.59.tgz",
"integrity": "sha512-8RkBivJrDCyPpBXhVZcjh7cQxVBSmRk9QM7hOketZzp6Tg79c0N8kkpAIito9bnJ3HCVCHVYz+KHTEbfQNfeVQ==",
"dev": true
},
"debug": {
"version": "2.6.9",
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
"integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
"dev": true,
"requires": {
"ms": "2.0.0"
}
},
"electron": {
"version": "1.8.8",
"resolved": "https://registry.npmjs.org/electron/-/electron-1.8.8.tgz",
"integrity": "sha512-1f9zJehcTTGjrkb06o6ds+gsRq6SYhZJyxOk6zIWjRH8hVy03y/RzUDELzNas71f5vcvXmfGVvyjeEsadDI8tg==",
"dev": true,
"requires": {
"@types/node": "^8.0.24",
"electron-download": "^3.0.1",
"extract-zip": "^1.0.3"
}
},
"electron-download": {
"version": "3.3.0",
"resolved": "https://registry.npmjs.org/electron-download/-/electron-download-3.3.0.tgz",
"integrity": "sha1-LP1U1pZsAZxNSa1l++Zcyc3vaMg=",
"dev": true,
"requires": {
"debug": "^2.2.0",
"fs-extra": "^0.30.0",
"home-path": "^1.0.1",
"minimist": "^1.2.0",
"nugget": "^2.0.0",
"path-exists": "^2.1.0",
"rc": "^1.1.2",
"semver": "^5.3.0",
"sumchecker": "^1.2.0"
}
},
"fs-extra": {
"version": "0.30.0",
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-0.30.0.tgz",
"integrity": "sha1-8jP/zAjU2n1DLapEl3aYnbHfk/A=",
"dev": true,
"requires": {
"graceful-fs": "^4.1.2",
"jsonfile": "^2.1.0",
"klaw": "^1.0.0",
"path-is-absolute": "^1.0.0",
"rimraf": "^2.2.8"
}
},
"jsonfile": {
"version": "2.4.0",
"resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-2.4.0.tgz",
"integrity": "sha1-NzaitCi4e72gzIO1P6PWM6NcKug=",
"dev": true,
"requires": {
"graceful-fs": "^4.1.6"
}
},
"ms": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=",
"dev": true
},
"sumchecker": {
"version": "1.3.1",
"resolved": "https://registry.npmjs.org/sumchecker/-/sumchecker-1.3.1.tgz",
"integrity": "sha1-ebs7RFbdBPGOvbwNcDodHa7FEF0=",
"dev": true,
"requires": {
"debug": "^2.2.0",
"es6-promise": "^4.0.5"
}
}
}
},
"@types/events": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/@types/events/-/events-3.0.0.tgz",
@ -4604,19 +4512,6 @@
}
}
},
"electron-json-storage": {
"version": "4.1.8",
"resolved": "https://registry.npmjs.org/electron-json-storage/-/electron-json-storage-4.1.8.tgz",
"integrity": "sha512-cBaxfSVG5SLWIvgkRJyl96W2VPCvvBcLjNaOfKC1oCENzStMt2BDzh/Qfxcz2M1mK4kNnsVv//CD46jIRrqWPw==",
"requires": {
"async": "^2.0.0",
"lockfile": "^1.0.4",
"lodash": "^4.0.1",
"mkdirp": "^0.5.1",
"rimraf": "^2.5.1",
"write-file-atomic": "^2.4.2"
}
},
"electron-mocha": {
"version": "8.2.0",
"resolved": "https://registry.npmjs.org/electron-mocha/-/electron-mocha-8.2.0.tgz",
@ -6897,12 +6792,6 @@
"react-is": "^16.7.0"
}
},
"home-path": {
"version": "1.0.7",
"resolved": "https://registry.npmjs.org/home-path/-/home-path-1.0.7.tgz",
"integrity": "sha512-tM1pVa+u3ZqQwIkXcWfhUlY3HWS3TsnKsfi2OHHvnhkX52s9etyktPyy1rQotkr0euWimChDq+QkQuDe8ngUlQ==",
"dev": true
},
"homedir-polyfill": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/homedir-polyfill/-/homedir-polyfill-1.0.3.tgz",
@ -7260,7 +7149,8 @@
"imurmurhash": {
"version": "0.1.4",
"resolved": "https://registry.npmjs.org/imurmurhash/-/imurmurhash-0.1.4.tgz",
"integrity": "sha1-khi5srkoojixPcT7a21XbyMUU+o="
"integrity": "sha1-khi5srkoojixPcT7a21XbyMUU+o=",
"dev": true
},
"in-publish": {
"version": "2.0.0",
@ -7913,15 +7803,6 @@
"integrity": "sha512-s5kLOcnH0XqDO+FvuaLX8DDjZ18CGFk7VygH40QoKPUQhW4e2rvM0rwUq0t8IQDOwYSeLK01U90OjzBTme2QqA==",
"dev": true
},
"klaw": {
"version": "1.3.1",
"resolved": "https://registry.npmjs.org/klaw/-/klaw-1.3.1.tgz",
"integrity": "sha1-QIhDO0azsbolnXh4XY6W9zugJDk=",
"dev": true,
"requires": {
"graceful-fs": "^4.1.9"
}
},
"known-css-properties": {
"version": "0.3.0",
"resolved": "https://registry.npmjs.org/known-css-properties/-/known-css-properties-0.3.0.tgz",
@ -8286,14 +8167,6 @@
}
}
},
"lockfile": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/lockfile/-/lockfile-1.0.4.tgz",
"integrity": "sha512-cvbTwETRfsFh4nHsL1eGWapU1XFi5Ot9E85sWAwia7Y7EgB7vfqcZhTKZ+l7hCGxSPoushMv5GKhT5PdLv03WA==",
"requires": {
"signal-exit": "^3.0.2"
}
},
"lodash": {
"version": "4.17.15",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz",
@ -14345,6 +14218,7 @@
"version": "2.4.3",
"resolved": "https://registry.npmjs.org/write-file-atomic/-/write-file-atomic-2.4.3.tgz",
"integrity": "sha512-GaETH5wwsX+GcnzhPgKcKjJ6M2Cq3/iZp1WyY/X1CSqrW+jVNM9Y7D8EC2sM4ZG/V8wZlSniJnCKWPmBYAucRQ==",
"dev": true,
"requires": {
"graceful-fs": "^4.1.11",
"imurmurhash": "^0.1.4",

View File

@ -60,7 +60,6 @@
"color": "^2.0.1",
"d3": "^4.13.0",
"debug": "^3.1.0",
"electron-json-storage": "^4.1.8",
"electron-updater": "4.0.6",
"etcher-sdk": "^3.0.1",
"flexboxgrid": "^6.3.0",
@ -91,7 +90,6 @@
"@types/bindings": "^1.3.0",
"@types/bluebird": "^3.5.30",
"@types/chai": "^4.2.7",
"@types/electron-json-storage": "^4.0.0",
"@types/mime-types": "^2.1.0",
"@types/mocha": "^5.2.7",
"@types/node": "^12.12.24",