Skip to content

armgit / Pake

Public Imported from GitHub
0

Turn any website into a lightweight desktop app with one command, on macOS, Windows and Linux.

refactor: inline AppImage failure guidance, drop single-use module

Tw93d1c564d43d70
diff --git a/bin/builders/BaseBuilder.ts b/bin/builders/BaseBuilder.ts
index 7abd3308..fc7ae651 100644
--- a/bin/builders/BaseBuilder.ts
+++ b/bin/builders/BaseBuilder.ts
@@ -25,7 +25,29 @@ import {
getInstallCommand,
getInstallTimeout,
} from './env';
-import { appendAppImageGuidance } from '@/utils/linuxBuildError';
+// Appended to the error when a Linux AppImage build fails for good. linuxdeploy's
+// diagnostics stream to the terminal (stdio: 'inherit') and never reach
+// error.message, so we cannot name the exact cause. We only reach here after
+// NO_STRIP=1 has been applied and still failed, so strip is shown as ruled out.
+const APPIMAGE_BAR = '━'.repeat(56);
+const APPIMAGE_FAILURE_GUIDANCE =
+ `\n\n${APPIMAGE_BAR}\n` +
+ 'Linux AppImage Build Failed\n' +
+ `${APPIMAGE_BAR}\n\n` +
+ 'The AppImage bundler (linuxdeploy) failed. Common causes and fixes:\n\n' +
+ ' • Strip incompatibility (glibc 2.38+): NO_STRIP=1 was already applied and\n' +
+ ' the build still failed, so strip is likely not the cause.\n' +
+ ' • Missing gdk-pixbuf loaders (e.g. "cannot stat\n' +
+ " '/usr/lib/gdk-pixbuf-2.0/...'\"): install them, then rebuild:\n" +
+ ' Arch: sudo pacman -S gdk-pixbuf2 librsvg\n' +
+ ' Debian: sudo apt install librsvg2-common gdk-pixbuf2.0-bin\n' +
+ ' Fedora: sudo dnf install gdk-pixbuf2-modules librsvg2\n' +
+ ' then: gdk-pixbuf-query-loaders --update-cache\n' +
+ ' • Running in Docker/container: AppImage needs /dev/fuse:\n' +
+ ' --privileged --device /dev/fuse --security-opt apparmor=unconfined\n\n' +
+ 'Still stuck? Build a DEB instead: pake <url> --targets deb\n' +
+ 'Detailed guide: https://github.com/tw93/Pake/blob/main/docs/faq.md\n' +
+ APPIMAGE_BAR;
export default abstract class BaseBuilder {
protected options: PakeAppOptions;
@@ -182,7 +204,8 @@ export default abstract class BaseBuilder {
// most common AppImage failure, so retry once with NO_STRIP=1; if that
// (or an already-NO_STRIP run) still fails, surface all known causes.
if (buildEnv.NO_STRIP) {
- throw appendAppImageGuidance(error);
+ (error as Error).message += APPIMAGE_FAILURE_GUIDANCE;
+ throw error;
}
logger.warn(
@@ -192,7 +215,8 @@ export default abstract class BaseBuilder {
try {
await shellExec(buildCommand, buildTimeout, resolveExecEnv());
} catch (retryError) {
- throw appendAppImageGuidance(retryError);
+ (retryError as Error).message += APPIMAGE_FAILURE_GUIDANCE;
+ throw retryError;
}
}
diff --git a/bin/utils/linuxBuildError.ts b/bin/utils/linuxBuildError.ts
deleted file mode 100644
index 06dc10a2..00000000
--- a/bin/utils/linuxBuildError.ts
+++ /dev/null
@@ -1,35 +0,0 @@
-const DIVIDER = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━';
-
-// Guidance printed after a Linux AppImage build fails for good. We cannot detect
-// the exact cause: linuxdeploy streams its diagnostics to the terminal via
-// `stdio: 'inherit'`, so they never reach `error.message` (which only holds the
-// failed command line). We only reach here after NO_STRIP=1 has already been
-// applied and still failed, so strip is presented as already ruled out.
-const APPIMAGE_FAILURE_GUIDANCE =
- `\n\n${DIVIDER}\n` +
- 'Linux AppImage Build Failed\n' +
- `${DIVIDER}\n\n` +
- 'The AppImage bundler (linuxdeploy) failed. Common causes and fixes:\n\n' +
- ' • Strip incompatibility (glibc 2.38+): NO_STRIP=1 was already applied and\n' +
- ' the build still failed, so strip is likely not the cause.\n' +
- ' • Missing gdk-pixbuf loaders (e.g. "cannot stat\n' +
- " '/usr/lib/gdk-pixbuf-2.0/...'\"): install them, then rebuild:\n" +
- ' Arch: sudo pacman -S gdk-pixbuf2 librsvg\n' +
- ' Debian: sudo apt install librsvg2-common gdk-pixbuf2.0-bin\n' +
- ' Fedora: sudo dnf install gdk-pixbuf2-modules librsvg2\n' +
- ' then: gdk-pixbuf-query-loaders --update-cache\n' +
- ' • Running in Docker/container: AppImage needs /dev/fuse:\n' +
- ' --privileged --device /dev/fuse --security-opt apparmor=unconfined\n\n' +
- 'Still stuck? Build a DEB instead: pake <url> --targets deb\n' +
- 'Detailed guide: https://github.com/tw93/Pake/blob/main/docs/faq.md\n' +
- DIVIDER;
-
-/**
- * Returns the original error with AppImage guidance appended to its message,
- * preserving the stack. Used when a Linux AppImage build fails for good.
- */
-export function appendAppImageGuidance(error: unknown): Error {
- const baseError = error instanceof Error ? error : new Error(String(error));
- baseError.message += APPIMAGE_FAILURE_GUIDANCE;
- return baseError;
-}
diff --git a/dist/cli.js b/dist/cli.js
index ba865e30..306d7e05 100644
--- a/dist/cli.js
+++ b/dist/cli.js
@@ -893,15 +893,14 @@ async function configureCargoRegistry(tauriSrcPath, useCnMirror) {
}
}
-const DIVIDER = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━';
-// Guidance printed after a Linux AppImage build fails for good. We cannot detect
-// the exact cause: linuxdeploy streams its diagnostics to the terminal via
-// `stdio: 'inherit'`, so they never reach `error.message` (which only holds the
-// failed command line). We only reach here after NO_STRIP=1 has already been
-// applied and still failed, so strip is presented as already ruled out.
-const APPIMAGE_FAILURE_GUIDANCE = `\n\n${DIVIDER}\n` +
+// Appended to the error when a Linux AppImage build fails for good. linuxdeploy's
+// diagnostics stream to the terminal (stdio: 'inherit') and never reach
+// error.message, so we cannot name the exact cause. We only reach here after
+// NO_STRIP=1 has been applied and still failed, so strip is shown as ruled out.
+const APPIMAGE_BAR = '━'.repeat(56);
+const APPIMAGE_FAILURE_GUIDANCE = `\n\n${APPIMAGE_BAR}\n` +
'Linux AppImage Build Failed\n' +
- `${DIVIDER}\n\n` +
+ `${APPIMAGE_BAR}\n\n` +
'The AppImage bundler (linuxdeploy) failed. Common causes and fixes:\n\n' +
' • Strip incompatibility (glibc 2.38+): NO_STRIP=1 was already applied and\n' +
' the build still failed, so strip is likely not the cause.\n' +
@@ -915,17 +914,7 @@ const APPIMAGE_FAILURE_GUIDANCE = `\n\n${DIVIDER}\n` +
' --privileged --device /dev/fuse --security-opt apparmor=unconfined\n\n' +
'Still stuck? Build a DEB instead: pake <url> --targets deb\n' +
'Detailed guide: https://github.com/tw93/Pake/blob/main/docs/faq.md\n' +
- DIVIDER;
-/**
- * Returns the original error with AppImage guidance appended to its message,
- * preserving the stack. Used when a Linux AppImage build fails for good.
- */
-function appendAppImageGuidance(error) {
- const baseError = error instanceof Error ? error : new Error(String(error));
- baseError.message += APPIMAGE_FAILURE_GUIDANCE;
- return baseError;
-}
-
+ APPIMAGE_BAR;
class BaseBuilder {
constructor(options) {
this.options = options;
@@ -1037,7 +1026,8 @@ class BaseBuilder {
// most common AppImage failure, so retry once with NO_STRIP=1; if that
// (or an already-NO_STRIP run) still fails, surface all known causes.
if (buildEnv.NO_STRIP) {
- throw appendAppImageGuidance(error);
+ error.message += APPIMAGE_FAILURE_GUIDANCE;
+ throw error;
}
logger.warn('⚠ AppImage build failed, retrying once with NO_STRIP=1 (common glibc 2.38+ strip issue).');
buildEnv = { ...buildEnv, NO_STRIP: '1' };
@@ -1045,7 +1035,8 @@ class BaseBuilder {
await shellExec(buildCommand, buildTimeout, resolveExecEnv());
}
catch (retryError) {
- throw appendAppImageGuidance(retryError);
+ retryError.message += APPIMAGE_FAILURE_GUIDANCE;
+ throw retryError;
}
}
// Copy app
diff --git a/tests/unit/linux-build-error.test.ts b/tests/unit/linux-build-error.test.ts
deleted file mode 100644
index d6bbad8b..00000000
--- a/tests/unit/linux-build-error.test.ts
+++ /dev/null
@@ -1,26 +0,0 @@
-import { describe, it, expect } from 'vitest';
-import { appendAppImageGuidance } from '@/utils/linuxBuildError';
-
-describe('appendAppImageGuidance', () => {
- it('appends guidance listing every known cause and the deb fallback', () => {
- const result = appendAppImageGuidance(new Error('boom'));
- expect(result.message).toContain('boom'); // original message preserved
- expect(result.message).toContain('Linux AppImage Build Failed');
- expect(result.message).toContain('NO_STRIP=1 was already applied');
- expect(result.message).toContain('gdk-pixbuf');
- expect(result.message).toContain('/dev/fuse');
- expect(result.message).toContain('--targets deb');
- });
-
- it('returns the same Error instance so the stack is preserved', () => {
- const original = new Error('Command failed with exit code 1');
- expect(appendAppImageGuidance(original)).toBe(original);
- });
-
- it('wraps non-Error throwables', () => {
- const result = appendAppImageGuidance('raw string failure');
- expect(result).toBeInstanceOf(Error);
- expect(result.message).toContain('raw string failure');
- expect(result.message).toContain('Linux AppImage Build Failed');
- });
-});