Skip to content

Commit

Permalink
Slightly better error messages on reading AudioProperties
Browse files Browse the repository at this point in the history
  • Loading branch information
nikhilm committed Nov 24, 2011
1 parent b41c16f commit 712fe3e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
24 changes: 24 additions & 0 deletions spec/taglibSpec.js
Expand Up @@ -59,6 +59,30 @@ vows.describe('taglib bindings')
}
},

'reading AudioProperties from non-existent file': {
topic: function() {
return function() {
return new Taglib.AudioProperties('thisfileobviouslyshouldnot.exist');
}
},

'should throw an exception': function(topic) {
assert.throws(topic, /readable/);
}
},

'reading AudioProperties from a non-audio file': {
topic: function() {
return function() {
return new Taglib.AudioProperties(__filename);
}
},

'should throw an exception': function(topic) {
assert.throws(topic, /extract audio properties/);
}
},

'writing Tags to File': {
topic: function() {
var filename = __dirname+'/sample-write.mp3';
Expand Down
10 changes: 7 additions & 3 deletions src/audioproperties.cc
Expand Up @@ -56,12 +56,16 @@ Handle<Value> AudioProperties::New(const Arguments &args) {

String::Utf8Value path(args[0]->ToString());

if (!TagLib::File::isReadable(*path)) {
std::string err = "File " + std::string(*path) + " is not readable";
return ThrowException(String::New(err.c_str(), err.length()));
}

TagLib::FileRef * f = new TagLib::FileRef(*path);
if ( f->isNull() || !f->audioProperties() )
{
std::string err = "Error while reading data from ";
err = err + std::string(*path);
return ThrowException( String::New( err.c_str(), err.length() ) );
std::string err = "Failed to extract audio properties from " + std::string(*path);
return ThrowException(String::New(err.c_str(),err.length()));
}

AudioProperties * properties = new AudioProperties(f);
Expand Down

0 comments on commit 712fe3e

Please sign in to comment.