Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
colltoaction opened this issue Apr 29, 2016 · 0 comments
Closed

Comments

@colltoaction
Copy link

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant