Skip to content

Commit

Permalink
/2
Browse files Browse the repository at this point in the history
  • Loading branch information
fregante committed Jul 27, 2024
1 parent 90a4888 commit 33c37c0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
2 changes: 0 additions & 2 deletions cli.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
#!/usr/bin/env node
import process from 'node:process';
import { init, errorHandler } from './core.js';

try {
await init();
} catch (error) {
errorHandler(error);
process.exitCode = 1;
}
12 changes: 11 additions & 1 deletion core.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import path from 'node:path';
import process from 'node:process';
import meow from 'meow';
import cleanStack from 'clean-stack';
import { upload, publish, fetchToken } from './wrapper.js';
import {
isUploadSuccess,
Expand Down Expand Up @@ -60,7 +62,15 @@ async function doPublish({ apiConfig, trustedTesters, deployPercentage }) {
}

export function errorHandler(error) {
console.log('❌', error?.response?.body ?? error?.message ?? error);
process.exitCode = 1;
if (error?.stack) {
// TODO: Use `pretty` after https://github.com/sindresorhus/clean-stack/issues/34
const lines = cleanStack(error.stack).split('\n');
console.error('❌', lines[0]);
console.log(lines.slice(1).join('\n'));
} else {
console.error('❌', error?.response?.body ?? error);
}

if (error?.name === 'HTTPError') {
const response = JSON.parse(error?.response?.body ?? '{}');
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
},
"dependencies": {
"chrome-webstore-upload": "^3.1.0",
"clean-stack": "^5.2.0",
"junk": "^4.0.1",
"meow": "^12.1.1",
"recursive-readdir": "^2.2.3",
Expand Down

0 comments on commit 33c37c0

Please sign in to comment.