Skip to content

Commit ad56c15

Browse files
authored
fix: Handle Can't find library error (#370)
* fix: Handle Can't find library error * revert safe options * refactor: ordering * fix: args
1 parent 7ff3fae commit ad56c15

File tree

6 files changed

+59
-56
lines changed

6 files changed

+59
-56
lines changed

lisp/_prepare.el

Lines changed: 46 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1432,7 +1432,14 @@ This uses function `locate-dominating-file' to look up directory tree."
14321432
(ignore-errors (make-directory package-user-dir t))
14331433
(eask--silent (eask-setup-paths))
14341434
(eask-with-verbosity 'debug (eask--load-config))
1435-
(eask--with-hooks ,@body))))))))))
1435+
(eask--with-hooks ,@body))))))
1436+
;; Report exit stats if any.
1437+
(eask--resolve-exit-status)))))
1438+
1439+
(defun eask--resolve-exit-status ()
1440+
"Resolve current exit status."
1441+
(when (memq 'error (eask--error-status))
1442+
(eask--exit 'failure)))
14361443

14371444
;;
14381445
;;; Eask file
@@ -1988,35 +1995,63 @@ Argument ARGS are direct arguments for functions `eask-error' or `eask-warn'."
19881995
(declare (indent 0) (debug t))
19891996
`(eask-ignore-errors (eask--silent-error ,@body)))
19901997

1991-
(defun eask--trigger-error ()
1992-
"Trigger error event."
1998+
(defun eask--error-status ()
1999+
"Return error status."
2000+
(let ((result))
2001+
;; Error.
2002+
(when eask--has-error-p
2003+
(push 'error result))
2004+
;; Warning.
2005+
(when eask--has-warn-p
2006+
(push (if (eask-strict-p)
2007+
'error
2008+
'warn)
2009+
result))
2010+
;; No repeat.
2011+
(delete-dups result)))
2012+
2013+
(defun eask--trigger-error (args)
2014+
"Trigger error event.
2015+
2016+
The argument ARGS is passed from the function `eask--error'."
2017+
(cond ((< emacs-major-version 28)
2018+
;; Handle https://github.com/emacs-eask/cli/issues/11.
2019+
(unless (string-prefix-p "Can't find library " (car args))
2020+
(setq eask--has-error-p t)))
2021+
(t
2022+
(setq eask--has-error-p t))) ; Just a record.
2023+
19932024
(when (and (not eask--ignore-error-p)
1994-
(not (eask-checker-p))) ; Ignore when checking Eask-file.
1995-
(if (eask-allow-error-p) ; Trigger error at the right time.
1996-
(add-hook 'eask-after-command-hook #'eask--exit)
1997-
(eask--exit))))
2025+
(not (eask-allow-error-p))
2026+
;; Ignore when checking Eask-file.
2027+
(not (eask-checker-p)))
2028+
;; Stop immediately.
2029+
(eask--exit 'failure)))
19982030

19992031
(defun eask--error (fnc &rest args)
20002032
"On error.
20012033
20022034
Arguments FNC and ARGS are used for advice `:around'."
2003-
(setq eask--has-error-p t) ; Just a record.
20042035
(let ((msg (eask--ansi 'error (apply #'format-message args))))
20052036
(unless eask-inhibit-error-message
20062037
(eask--unsilent (eask-msg "%s" msg)))
20072038
(run-hook-with-args 'eask-on-error-hook 'error msg)
2008-
(eask--trigger-error))
2039+
(eask--trigger-error args))
20092040
(when debug-on-error (apply fnc args)))
20102041

2042+
(defun eask--trigger-warn ()
2043+
"Trigger warning event."
2044+
(setq eask--has-warn-p t)) ; Just a record.
2045+
20112046
(defun eask--warn (fnc &rest args)
20122047
"On warn.
20132048
20142049
Arguments FNC and ARGS are used for advice `:around'."
2015-
(setq eask--has-warn-p t) ; Just a record.
20162050
(let ((msg (eask--ansi 'warn (apply #'format-message args))))
20172051
(unless eask-inhibit-error-message
20182052
(eask--unsilent (eask-msg "%s" msg)))
2019-
(run-hook-with-args 'eask-on-warning-hook 'warn msg))
2053+
(run-hook-with-args 'eask-on-warning-hook 'warn msg)
2054+
(eask--trigger-warn))
20202055
(eask--silent (apply fnc args)))
20212056

20222057
;; Don't pollute outer exection.

test/jest/exec.test.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
1-
const cmp = require('semver-compare');
21
const { emacsVersion, TestContext } = require("./helpers");
32

43
describe("exec", () => {
54
const ctx = new TestContext("./test/jest/exec");
65

76
beforeAll(async () => {
87
await ctx.runEask(
9-
"install-deps", { timeout: 40000 },
10-
// See https://github.com/emacs-eask/cli/issues/11.
11-
cmp(await emacsVersion(), "28.1") == -1);
8+
"install-deps", { timeout: 40000 });
129
});
1310

1411
afterAll(() => ctx.cleanUp());

test/jest/helpers.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,8 @@ class TestContext {
160160
* @param {any} config
161161
* @returns {Promise.<CommandOutput>}
162162
*/
163-
runEask(command, config, safe = false) {
164-
return this.run(this.easkCommand + " " + command, config, safe);
163+
runEask(command, config) {
164+
return this.run(this.easkCommand + " " + command, config);
165165
}
166166

167167
/**
@@ -173,7 +173,7 @@ class TestContext {
173173
* @param {any} config
174174
* @returns {Promise.<CommandOutput>}
175175
*/
176-
run(command, config, safe = false) {
176+
run(command, config) {
177177
return exec(command, {
178178
cwd: this.cwd,
179179
signal: this.controller.signal,
@@ -191,9 +191,6 @@ class TestContext {
191191
return new CommandOutput(obj, this.cwd);
192192
})
193193
.catch((err) => {
194-
if (safe)
195-
return this.errorToCommandOutput(err);
196-
197194
if (!err.code)
198195
err.message += "\nexec: TIMEOUT";
199196

test/jest/install.test.js

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ describe("install and uninstall", () => {
1414

1515
it("installs project package", async () => {
1616
// creates dist/<pkg>.tar
17-
await ctx.runEask("package", { timeout: 40000 },
18-
// See https://github.com/emacs-eask/cli/issues/11.
19-
cmp(await emacsVersion(), "28.1") == -1);
17+
await ctx.runEask("package");
2018
// installs dependencies and generated package
2119
await ctx.runEask("install");
2220
const { stderr } = await ctx.runEask("list");
@@ -41,18 +39,13 @@ describe("install and uninstall", () => {
4139
});
4240

4341
it("uninstalls project package", async () => {
44-
await ctx.runEask("uninstall", { timeout: 40000 },
45-
// See https://github.com/emacs-eask/cli/issues/11.
46-
cmp(await emacsVersion(), "28.1") == -1);
42+
await ctx.runEask("uninstall");
4743
const { stderr } = await ctx.runEask("list");
4844
expect(stderr).not.toMatch(packageName);
4945
});
5046

5147
it("installs dependencies", async () => {
52-
const { stderr } = await ctx.runEask(
53-
"install-deps", { timeout: 40000 },
54-
// See https://github.com/emacs-eask/cli/issues/11.
55-
cmp(await emacsVersion(), "28.1") == -1);
48+
const { stderr } = await ctx.runEask("install-deps");
5649
expect(stderr).not.toMatch(packageName);
5750
});
5851

test/jest/local.test.js

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@ describe("local", () => {
1515
// this is because of recipe dependencies triggering
1616
// "temporary archives" build.
1717
beforeAll(async () => {
18-
await ctx.runEask(
19-
"install-deps", { timeout: 40000 },
20-
// See https://github.com/emacs-eask/cli/issues/11.
21-
cmp(await emacsVersion(), "28.1") == -1);
18+
await ctx.runEask("install-deps", { timeout: 40000 });
2219
});
2320

2421
afterAll(() => ctx.cleanUp());
@@ -84,10 +81,7 @@ describe("local", () => {
8481

8582
describe("Development", () => {
8683
beforeAll(async () => {
87-
await ctx.runEask(
88-
"install-deps", { timeout: 40000 },
89-
// See https://github.com/emacs-eask/cli/issues/11.
90-
cmp(await emacsVersion(), "28.1") == -1)
84+
await ctx.runEask("install-deps", { timeout: 40000 });
9185
});
9286

9387
// this requires install-deps
@@ -123,9 +117,7 @@ describe("local", () => {
123117

124118
describe("Execution", () => {
125119
beforeAll(async () => {
126-
await ctx.runEask("install-deps", { timeout: 40000 },
127-
// See https://github.com/emacs-eask/cli/issues/11.
128-
cmp(await emacsVersion(), "28.1") == -1)
120+
await ctx.runEask("install-deps", { timeout: 40000 });
129121
});
130122

131123
test("eval", async () => {
@@ -212,15 +204,14 @@ describe("local", () => {
212204
describe("Linting", () => {
213205
// some lint commands may fail if packages are missing
214206
beforeAll(async () => {
215-
await ctx.runEask("install-deps", { timeout: 40000 },
216-
// See https://github.com/emacs-eask/cli/issues/11.
217-
cmp(await emacsVersion(), "28.1") == -1)
207+
await ctx.runEask("install-deps", { timeout: 40000 });
218208
});
219209

220210
it.each([
221211
"lint checkdoc",
222212
"lint declare",
223213
"lint elint",
214+
"lint elisp-lint",
224215
"lint indent",
225216
"lint keywords",
226217
"lint license",
@@ -234,12 +225,6 @@ describe("local", () => {
234225
await ctx.runEask("lint elsa");
235226
});
236227

237-
it("lint elint", async () => {
238-
await ctx.runEask("lint elisp-lint", { },
239-
// See https://github.com/emacs-eask/cli/issues/11.
240-
cmp(await emacsVersion(), "28.1") == -1);
241-
});
242-
243228
it("lint regexps", async () => {
244229
if (cmp(await emacsVersion(), "27.1") == 1) {
245230
await ctx.runEask("lint regexps");

test/jest/outdated-upgrade.test.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
1-
const cmp = require('semver-compare');
21
const { emacsVersion, TestContext } = require("./helpers");
32

43
describe("outdated and upgrade", () => {
54
const ctx = new TestContext("./test/jest/outdated-upgrade");
65

76
beforeAll(async () => {
8-
await ctx.runEask(
9-
"install-deps", { timeout: 40000 },
10-
// See https://github.com/emacs-eask/cli/issues/11.
11-
cmp(await emacsVersion(), "28.1") == -1);
7+
await ctx.runEask("install-deps", { timeout: 40000 });
128
await ctx.runEask("load make-outdate.el");
139
});
1410

0 commit comments

Comments
 (0)