Skip to content
This repository has been archived by the owner on Nov 12, 2019. It is now read-only.

Commit

Permalink
fix(errors): show verbose error for duplicate files
Browse files Browse the repository at this point in the history
progress #14
  • Loading branch information
Mahdi Dibaiee committed Oct 24, 2015
1 parent 629b6f7 commit f0f6a68
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 6 deletions.
14 changes: 11 additions & 3 deletions build/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -41075,6 +41075,12 @@ var readFile = _asyncToGenerator(function* (path) {
exports.readFile = readFile;

var writeFile = _asyncToGenerator(function* (path, content) {
try {
var file = yield getFile(path);

return Promise.reject(new Error('File already exists: ' + path));
} catch (e) {}

var request = sdcard().addNamed(content, path);

return new Promise(function (resolve, reject) {
Expand Down Expand Up @@ -41258,7 +41264,6 @@ var Breadcrumb = (function (_Component) {
var els = [];

if (this.props.search) {
console.log('search');
els = [_react2['default'].createElement(
'span',
{ key: '000' },
Expand Down Expand Up @@ -43434,18 +43439,20 @@ exports['default'] = function (state, action) {
});
}

console.log('readFile', path);
return (0, _apiFiles.readFile)(path).then(function (content) {
console.log('readFile done', path);
archive.file(archivePath + '/' + file.name, content);
});
}));

all.then(function () {
var buffer = archive.generate({ type: 'nodebuffer' });
console.log(buffer);
var blob = new Blob([buffer], { type: 'application/zip' });

var cwd = _store2['default'].getState().get('cwd');
var path = (0, _utils.normalize)(cwd + '/' + action.name);
console.log(path);
return (0, _apiFiles.writeFile)(path, blob);
}).then(boundRefresh)['catch'](_utils.reportError);

Expand Down Expand Up @@ -44021,7 +44028,8 @@ function getKey(object, key) {

function reportError(err) {
console.error(err);
var action = (0, _actionsDialog.show)('errorDialog', { description: err.message });
var msg = err.message || err.target.error.message;
var action = (0, _actionsDialog.show)('errorDialog', { description: msg });
_store2['default'].dispatch(action);
}

Expand Down
9 changes: 9 additions & 0 deletions src/js/api/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,15 @@ export async function readFile(path) {
}

export async function writeFile(path, content) {
try {
let file = await getFile(path);

return Promise.reject(new Error('File already exists: ' + path));
} catch(e) {

}


let request = sdcard().addNamed(content, path);

return new Promise((resolve, reject) => {
Expand Down
1 change: 0 additions & 1 deletion src/js/components/breadcrumb.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ export default class Breadcrumb extends Component {
let els = [];

if (this.props.search) {
console.log('search');
els = [
<span key='000'>Search: {this.props.search}</span>
]
Expand Down
4 changes: 3 additions & 1 deletion src/js/reducers/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,18 +107,20 @@ export default function(state = [], action) {
})
}

console.log('readFile', path);
return readFile(path).then(content => {
console.log('readFile done', path);
archive.file(archivePath + '/' + file.name, content);
});
}))

all.then(() => {
let buffer = archive.generate({ type: 'nodebuffer' });
console.log(buffer);
let blob = new Blob([buffer], { type: 'application/zip' });

let cwd = store.getState().get('cwd');
let path = normalize(cwd + '/' + action.name);
console.log(path);
return writeFile(path, blob);
}).then(boundRefresh).catch(reportError);

Expand Down
3 changes: 2 additions & 1 deletion src/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ export function getKey(object = store.getState().toJS(), key) {

export function reportError(err) {
console.error(err);
let action = show('errorDialog', {description: err.message});
let msg = err.message || err.target.error.message;
let action = show('errorDialog', {description: msg});
store.dispatch(action);
}

Expand Down

0 comments on commit f0f6a68

Please sign in to comment.