Lagrange [work/v1.7]

Report errors in MIME hooks; added to about:debug

=> 10d5a1ea2ded21623d1abcb6a955f5098faad334

diff --git a/src/app.c b/src/app.c
index ba7d41d2..da6a343f 100644
--- a/src/app.c
+++ b/src/app.c
@@ -502,6 +502,8 @@ const iString *debugInfo_App(void) {
     iConstForEach(StringList, j, d->launchCommands) {
         appendFormat_String(msg, "%s\n", cstr_String(j.value));
     }
+    appendFormat_String(msg, "## MIME hooks\n");
+    append_String(msg, debugInfo_MimeHooks(d->mimehooks));
     return msg;
 }
 
@@ -1034,7 +1036,13 @@ iBool willUseProxy_App(const iRangecc scheme) {
 
 iBool handleCommand_App(const char *cmd) {
     iApp *d = &app_;
-    if (equal_Command(cmd, "prefs.dialogtab")) {
+    if (equal_Command(cmd, "config.error")) {
+        makeMessage_Widget(uiTextCaution_ColorEscape "CONFIG ERROR",
+                           format_CStr("Error in config file: %s\nSee \"about:debug\" for details.",
+                                       suffixPtr_Command(cmd, "where")));
+        return iTrue;
+    }
+    else if (equal_Command(cmd, "prefs.dialogtab")) {
         d->prefs.dialogTab = arg_Command(cmd);
         return iTrue;
     }
diff --git a/src/mimehooks.c b/src/mimehooks.c
index 8bb838ef..fd535643 100644
--- a/src/mimehooks.c
+++ b/src/mimehooks.c
@@ -1,6 +1,8 @@
 #include "mimehooks.h"
+#include "app.h"
 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -23,6 +25,7 @@ void deinit_FilterHook(iFilterHook *d) {
 
 void setMimePattern_FilterHook(iFilterHook *d, const iString *pattern) {
     iReleasePtr(&d->mimeRegex);
+    set_String(&d->mimePattern, pattern);
     d->mimeRegex = new_RegExp(cstr_String(pattern), caseInsensitive_RegExpOption);
 }
 
@@ -105,6 +108,7 @@ iBlock *tryFilter_MimeHooks(const iMimeHooks *d, const iString *mime, const iBlo
 static const char *mimeHooksFilename_MimeHooks_ = "mimehooks.txt";
 
 void load_MimeHooks(iMimeHooks *d, const char *saveDir) {
+    iBool reportError = iFalse;
     iFile *f = newCStr_File(concatPath_CStr(saveDir, mimeHooksFilename_MimeHooks_));
     if (open_File(f, read_FileMode | text_FileMode)) {
         iBlock * src     = readAll_File(f);
@@ -124,6 +128,15 @@ void load_MimeHooks(iMimeHooks *d, const char *saveDir) {
                 setRange_String(&hook->label, lines[0]);
                 setMimePattern_FilterHook(hook, collect_String(newRange_String(lines[1])));
                 setCommand_FilterHook(hook, collect_String(newRange_String(lines[2])));
+                /* Check if commmand is valid. */ {
+                    iRangecc seg = iNullRange;
+                    while (nextSplit_Rangecc(range_String(&hook->command), ";", &seg)) {
+                        if (!fileExistsCStr_FileInfo(cstr_Rangecc(seg))) {
+                            reportError = iTrue;
+                        }
+                        break;
+                    }
+                }
                 pushBack_PtrArray(&d->filters, hook);
                 pos = 0;
             }
@@ -131,9 +144,37 @@ void load_MimeHooks(iMimeHooks *d, const char *saveDir) {
         delete_Block(src);
     }
     iRelease(f);
+    if (reportError) {
+        postCommand_App("~config.error where:mimehooks.txt");
+    }
 }
 
 void save_MimeHooks(const iMimeHooks *d) {
     iUnused(d);
 }
 
+const iString *debugInfo_MimeHooks(const iMimeHooks *d) {
+    iString *str = collectNew_String();
+    size_t index = 0;
+    iConstForEach(PtrArray, i, &d->filters) {
+        const iFilterHook *filter = i.ptr;
+        appendFormat_String(str, "### %d: %s\n", index, cstr_String(&filter->label));
+        appendFormat_String(str, "MIME regex:\n```\n%s\n```\n", cstr_String(&filter->mimePattern));
+        iStringList *args = iClob(split_String(&filter->command, ";"));
+        if (isEmpty_StringList(args)) {
+            appendFormat_String(str, "\u26a0 Command not specified!\n");
+            continue;
+        }
+        const iString *exec = constAt_StringList(args, 0);
+        if (isEmpty_String(exec)) {
+            appendFormat_String(str, "\u26a0 Command not specified!\n");
+        }
+        else {
+            appendFormat_String(str, "Executable: %s\n```\n%s\n```\n",
+                                fileExists_FileInfo(exec) ? "" : "\u26a0 FILE NOT FOUND",
+                                cstr_String(exec));
+        }
+        index++;
+    }
+    return str;
+}
diff --git a/src/mimehooks.h b/src/mimehooks.h
index c78a3c86..7a8cd2c9 100644
--- a/src/mimehooks.h
+++ b/src/mimehooks.h
@@ -29,3 +29,5 @@ iBlock *    tryFilter_MimeHooks     (const iMimeHooks *, const iString *mime,
 
 void        load_MimeHooks          (iMimeHooks *, const char *saveDir);
 void        save_MimeHooks          (const iMimeHooks *);
+
+const iString *debugInfo_MimeHooks  (const iMimeHooks *);
Proxy Information
Original URL
gemini://git.skyjake.fi/lagrange/work%2Fv1.7/cdiff/10d5a1ea2ded21623d1abcb6a955f5098faad334
Status Code
Success (20)
Meta
text/gemini; charset=utf-8
Capsule Response Time
55.998903 milliseconds
Gemini-to-HTML Time
0.567562 milliseconds

This content has been proxied by September (ba2dc).