Skip to content

Commit

Permalink
eslint: Enable "prefer-promise-reject-errors" rule
Browse files Browse the repository at this point in the history
  • Loading branch information
martinpitt authored and mvollmer committed May 15, 2018
1 parent 87deca1 commit ea516f0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"ignoredNodes": [ "JSXAttribute" ]
}],
"newline-per-chained-call": ["error", { "ignoreChainWithDepth": 2 }],
"prefer-promise-reject-errors": ["error", { "allowEmptyReject": true }],
"react/jsx-indent": ["error", 4],

"camelcase": "off",
Expand All @@ -41,7 +42,6 @@
"eqeqeq": "off",
"import/no-webpack-loader-syntax": "off",
"object-property-newline": "off",
"prefer-promise-reject-errors": "off",
"react/jsx-no-bind": "off"
},
"globals": {
Expand Down
2 changes: 1 addition & 1 deletion pkg/apps/packagekit.es6
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function resolve(method, filter, name, progress_cb) {
return resolve_many(method, filter, [ name ], progress_cb)
.then(function (ids) {
if (ids.length === 0)
return Promise.reject({ detail: "Can't resolve package", code: "not-found" });
return Promise.reject(new PK.TransactionError("not-found", "Can't resolve package"));
else
return ids[0];
});
Expand Down
12 changes: 10 additions & 2 deletions pkg/lib/packagekit.es6
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,14 @@ export function transaction(method, arglist, signalHandlers, notifyHandler) {
});
}

export class TransactionError extends Error {
constructor(code, detail) {
super(detail);
this.detail = detail;
this.code = code;
}
}

/**
* Run a long cancellable PackageKit transaction
*
Expand All @@ -189,7 +197,7 @@ export function transaction(method, arglist, signalHandlers, notifyHandler) {
* be called to cancel the current transaction. if wait is true, PackageKit is waiting for its lock (i. e.
* on another package operation)
* signalHandlers, notifyHandler: As in method #transaction, but ErrorCode and Finished are handled internally
* Returns: Promise that resolves when the transaction finished successfully, or rejects with {detail, code}
* Returns: Promise that resolves when the transaction finished successfully, or rejects with TransactionError
* on failure.
*/
export function cancellableTransaction(method, arglist, progress_cb, signalHandlers) {
Expand Down Expand Up @@ -237,7 +245,7 @@ export function cancellableTransaction(method, arglist, progress_cb, signalHandl
// avoid calling progress_cb after ending the transaction, to avoid flickering cancel buttons
ErrorCode: (code, detail) => {
progress_cb = null;
reject({ detail, code: cancelled ? "cancelled" : code });
reject(new TransactionError(cancelled ? "cancelled" : code, detail));
},
Finished: (exit, runtime) => {
progress_cb = null;
Expand Down

0 comments on commit ea516f0

Please sign in to comment.