Skip to content

Commit

Permalink
Embrace native file error messages for cml-publish
Browse files Browse the repository at this point in the history
  • Loading branch information
0x2b3bfa0 committed Mar 6, 2021
1 parent 5b9abe9 commit 303b773
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 14 deletions.
6 changes: 2 additions & 4 deletions bin/cml-publish.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,8 @@ describe('CML e2e', () => {

test('cml-publish /nonexistent produces file error', async () => {
await expect(
exec(`echo none | node ./bin/cml-publish.js /nonexistent`)
).rejects.toThrowError(
'Path /nonexistent does not exist or is not a readable file'
);
exec('echo none | node ./bin/cml-publish.js /nonexistent')
).rejects.toThrowError('ENOENT: no such file or directory, stat');
});

test('echo invalid | cml-publish produces buffer mime type error', async () => {
Expand Down
12 changes: 2 additions & 10 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,9 @@ const mime_type = async (opts) => {
const fetch_upload_data = async (opts) => {
const { path, buffer } = opts;

if (path) {
try {
await fs.promises.access(path, fs.constants.F_OK | fs.constants.R_OK);
} catch (err) {
throw new Error(`Path ${path} does not exist or is not a readable file`);
}
}

const mime = await mime_type(opts);
const data = path ? fs.createReadStream(path) : buffer;
const size = path ? (await fs.promises.stat(path)).size : buffer.length;
const data = path ? fs.createReadStream(path) : buffer;
const mime = await mime_type(opts);

return { mime, size, data };
};
Expand Down

0 comments on commit 303b773

Please sign in to comment.