timheuer / taglib-sharp-portable

.NET Portable Class Library implementation of TagLib# (forked from TagLib# main project)
Other
58 stars 33 forks source link

Better error reports when passing an invalid name to File.Create #15

Closed colltoaction closed 2 years ago

colltoaction commented 8 years ago

I got this cryptic error the first time I tried to use File.Create:

An exception of type 'TagLib.UnsupportedFormatException' occurred in TagLib.Portable.dll but was not handled in user code

Additional information: streamname (taglib/)

I had to dig a little bit until I found that TagLib requires me to add an extension to the stream name if the mimetype is missing (https://github.com/timheuer/taglib-sharp-portable/blob/master/src/TagLib.Shared/TagLib/File.cs#L1264).

I'm not really sure why we ask for a stream name (other than guessing a mimetype), but it would be great if this behavior was documented somewhere or the error was more explicit.

I'm thinking something like the following could work:


                if(index >= 1 && index < abstraction.Name.Length)
                    ext = abstraction.Name.Substring (index,
                        abstraction.Name.Length - index);

                if (string.IsNullOrWhiteSpace(ext))
                    throw new UnsupportedFormatException (
                        String.Format (
                            CultureInfo.InvariantCulture,
                            "If a mimetype is not specified, then the IFileAbstraction name should have a file extension"));

                mimetype = "taglib/" + ext.ToLower();

Thanks!