Navigation Menu

Skip to content

Commit

Permalink
Check existence of the source file before processing
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Aug 9, 2012
1 parent 4e4f0a8 commit 6a7a107
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions bin/gcs-post-sdf
Expand Up @@ -27,6 +27,11 @@ if (!commandLine.options.source) {
var sourceFile = CLI.resolve(commandLine.options.source);
console.log('Processing: %s', sourceFile);

if (!path.existsSync(sourceFile)) {
console.log('No such file');
return process.exit(1);
}

var format = sourceFile.match(/\.(xml|json)$/i);
if (!format) {
console.log('Unknown format');
Expand All @@ -41,26 +46,27 @@ if (format != 'json') {
return process.exit(1);
}

var sourceText = fs.readFileSync(sourceFile, 'UTF-8');
var batches = JSON.parse(sourceText);
var processor = new BatchProcessor({
context: commandLine.context,
domain: commandLine.domain
});

try {
processor.validate(batches);
} catch (error) {
console.log('Validation failed.');
console.log(error.errors.join('\n'));
return process.exit(1);
}
var batches = fs.readFileSync(sourceFile, 'UTF-8');
batches = JSON.parse(batches);
var processor = new BatchProcessor({
context: commandLine.context,
domain: commandLine.domain
});

try {
processor.validate(batches);
} catch (error) {
console.log('Validation failed.');
console.log(error.errors.join('\n'));
return process.exit(1);
}

try {
var result = processor.loadSync(batches);
console.log('Status: %s', result.status);
console.log('Added: %s', result.adds);
console.log('Deleted: %s', result.deletes);

} catch(error) {
console.log('Fatal error!');
console.log(error.message + '\n' + error.stack);
Expand Down

0 comments on commit 6a7a107

Please sign in to comment.