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

Improve the "unsupported format" error message #461

Merged
merged 1 commit into from
Sep 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions documentation/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,26 @@ decode the binary content as a text and corrupt it. See
That happens if you try to handle to much data with the synchronous API. If
possible, try the asynchronous API, see
[this page]({{site.baseurl}}/documentation/limitations.html) for more informations.

### Can't read the data of [...]. Is it in a supported JavaScript type ?

Or the old message:

> The data of [...] is in an unsupported format

The method [`file(name, data [,options])`]({{site.baseurl}}/documentation/api_jszip/file_data.html)
accepts string and binary inputs for `data`.

If you use an unsupported type, an object for example, you will get this error:

```js
// WRONG
var data = {
content: new ArrayBuffer(...)
};
zip.file("my.data", data); // won't work, data is an object

// CORRECT
var data = new ArrayBuffer(...);
zip.file("my.data", data); // will work, JSZip accepts ArrayBuffer
```
3 changes: 2 additions & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,8 @@ exports.prepareContent = function(name, inputData, isBinary, isOptimizedBinarySt

if (!dataType) {
return external.Promise.reject(
new Error("The data of '" + name + "' is in an unsupported format !")
new Error("Can't read the data of '" + name + "'. Is it " +
"in a supported JavaScript type (String, Blob, ArrayBuffer, etc) ?")
);
}
// special case : it's way easier to work with Uint8Array than with ArrayBuffer
Expand Down
2 changes: 1 addition & 1 deletion test/asserts/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ QUnit.module("file", function () {
ok(false, "An unsupported object was added, but no exception thrown");
}, function (e) {
start();
ok(e.message.match("unsupported format"), "the error message is useful");
ok(e.message.match("Is it in a supported JavaScript type"), "the error message is useful");
});
});

Expand Down