Permalink
Browse files

Changed saveSync semantics to throw an exception

  • Loading branch information...
1 parent 3264ffa commit ecf3b1a10bccee38b53f63e42f473f5642c6a957 @nikhilm committed May 29, 2012
Showing with 25 additions and 2 deletions.
  1. +2 −1 README.md
  2. +15 −0 spec/buffersSpec.js
  3. +8 −1 src/tag.cc
View
@@ -143,7 +143,8 @@ will be `null` if the save was successful, otherwise it will be an object with
### Tag.saveSync()
-Save any changes in the Tag meta-data to disk _synchronously_.
+Save any changes in the Tag meta-data to disk _synchronously_. Throws an
+exception if the save failed.
### Tag.isEmpty()
View
@@ -163,5 +163,20 @@ vows.describe('taglib bindings: Buffers')
'should lead to empty tags': function(tag) {
assert.isObject(tag);
}
+ },
+
+ 'writing to a tag from a buffer': {
+ topic: function() {
+ return function() {
+ var buf = fs.readFileSync(__dirname+'/sample.mp3');
+ var tag = Taglib.tagSync(buf, 'mpeg');
+ tag.artist = 'nsm';
+ tag.saveSync();
+ }
+ },
+
+ 'should fail': function(topic) {
+ assert.throws(topic);
+ }
}
}).export(module);
View
@@ -142,7 +142,14 @@ Handle<Value> Tag::SyncSaveTag(const Arguments &args) {
HandleScope scope;
Tag *t = ObjectWrap::Unwrap<Tag>(args.This());
assert(t->fileRef);
- return Boolean::New(t->fileRef->save());
+ bool success = t->fileRef->save();
+ if (success)
+ return Undefined();
+ else
+ return ThrowException(String::Concat(
+ String::New("Failed to save file: "),
+ String::New(t->fileRef->file()->name())
+ ));
}
Handle<Value> Tag::SyncTag(const Arguments &args) {

0 comments on commit ecf3b1a

Please sign in to comment.