Browse Source

feat: show fatal error note inline

+ remove stack info from error message as it's auto-added anyway
tophf 2 years ago
parent
commit
c318836fe7
2 changed files with 22 additions and 12 deletions
  1. 2 4
      src/background/index.js
  2. 20 8
      src/options/views/edit/index.vue

+ 2 - 4
src/background/index.js

@@ -100,10 +100,8 @@ async function handleCommandMessage({ cmd, data, [kTop]: mode } = {}, src) {
   } catch (err) {
   } catch (err) {
     if (process.env.DEBUG) console.error(err);
     if (process.env.DEBUG) console.error(err);
     // Adding `stack` info + in FF a rejected Promise value is transferred only for an Error object
     // Adding `stack` info + in FF a rejected Promise value is transferred only for an Error object
-    throw err instanceof SafeError
-      ? (IS_FIREFOX && (err.message += ` [${VIOLENTMONKEY}]\n${err.stack}`), err)
-      : new SafeError((isObject(err) ? JSON.stringify(err) : err) +
-        ` in ${cmd}(${data == null ? data : JSON.stringify(data)})`);
+    throw err instanceof SafeError ? err
+      : new SafeError(isObject(err) ? JSON.stringify(err) : err);
   }
   }
 }
 }
 
 

+ 20 - 8
src/options/views/edit/index.vue

@@ -22,19 +22,24 @@
       </div>
       </div>
       <div class="mr-1">
       <div class="mr-1">
         <button v-text="i18n('buttonSave')" @click="save" :disabled="!canSave"
         <button v-text="i18n('buttonSave')" @click="save" :disabled="!canSave"
-                :class="{'has-error': errors}" :title="errors"/>
+                :class="{'has-error': fatal || errors}" :title="fatal || errors"/>
         <button v-text="i18n('buttonSaveClose')" @click="saveClose" :disabled="!canSave"/>
         <button v-text="i18n('buttonSaveClose')" @click="saveClose" :disabled="!canSave"/>
         <button v-text="i18n('buttonClose')" @click="close"/>
         <button v-text="i18n('buttonClose')" @click="close"/>
       </div>
       </div>
     </div>
     </div>
 
 
-    <div class="frozen-note mr-2c flex flex-wrap" v-if="note && nav === 'code'">
+    <div class="frozen-note shelf mr-2c flex flex-wrap" v-if="note && nav === 'code'">
       <p v-text="i18n('readonlyNote')"/>
       <p v-text="i18n('readonlyNote')"/>
       <keep-alive>
       <keep-alive>
         <VMSettingsUpdate class="flex ml-2c" :script="script"/>
         <VMSettingsUpdate class="flex ml-2c" :script="script"/>
       </keep-alive>
       </keep-alive>
     </div>
     </div>
 
 
+    <p v-if="fatal" class="shelf fatal">
+      <b v-text="fatal[0]"/>
+      {{fatal[1]}}
+    </p>
+
     <vm-code
     <vm-code
       class="flex-auto"
       class="flex-auto"
       :value="code"
       :value="code"
@@ -69,7 +74,7 @@
     />
     />
     </keep-alive>
     </keep-alive>
 
 
-    <div v-if="errors" class="errors my-1c">
+    <div v-if="errors" class="errors shelf my-1c">
       <p v-for="e in errors" :key="e" v-text="e" class="text-red"/>
       <p v-for="e in errors" :key="e" v-text="e" class="text-red"/>
       <p class="my-1">
       <p class="my-1">
         <a :href="urlMatching" target="_blank" rel="noopener noreferrer" v-text="urlMatching"/>
         <a :href="urlMatching" target="_blank" rel="noopener noreferrer" v-text="urlMatching"/>
@@ -85,7 +90,7 @@ import {
   sendCmdDirectly, trueJoin,
   sendCmdDirectly, trueJoin,
 } from '@/common';
 } from '@/common';
 import { deepCopy, deepEqual, objectPick } from '@/common/object';
 import { deepCopy, deepEqual, objectPick } from '@/common/object';
-import { showConfirmation, showMessage } from '@/common/ui';
+import { showMessage } from '@/common/ui';
 import { keyboardService } from '@/common/keyboard';
 import { keyboardService } from '@/common/keyboard';
 import VmCode from '@/common/ui/code';
 import VmCode from '@/common/ui/code';
 import VmExternals from '@/common/ui/externals';
 import VmExternals from '@/common/ui/externals';
@@ -193,6 +198,7 @@ export default {
       },
       },
       hotkeys: null,
       hotkeys: null,
       errors: null,
       errors: null,
+      fatal: null,
       frozen: false,
       frozen: false,
       note: false,
       note: false,
       urlMatching: 'https://violentmonkey.github.io/api/matching/',
       urlMatching: 'https://violentmonkey.github.io/api/matching/',
@@ -291,6 +297,7 @@ export default {
       const { config, custom } = script;
       const { config, custom } = script;
       const { notifyUpdates } = config;
       const { notifyUpdates } = config;
       const { noframes } = custom;
       const { noframes } = custom;
+      let fatal;
       try {
       try {
         const codeComponent = this.$refs.code;
         const codeComponent = this.$refs.code;
         const id = script.props.id;
         const id = script.props.id;
@@ -322,10 +329,9 @@ export default {
         this.script = res.update; // triggers onScript+onChange to handle the new `meta` and `props`
         this.script = res.update; // triggers onScript+onChange to handle the new `meta` and `props`
         if (newId && !id) history.replaceState(null, this.scriptName, `${ROUTE_SCRIPTS}/${newId}`);
         if (newId && !id) history.replaceState(null, this.scriptName, `${ROUTE_SCRIPTS}/${newId}`);
       } catch (err) {
       } catch (err) {
-        showConfirmation(`${err.message || err}`, {
-          cancel: false,
-        });
+        fatal = err.message.split('\n');
       }
       }
+      this.fatal = fatal;
     },
     },
     close(cm) {
     close(cm) {
       if (cm && this.nav !== 'code') {
       if (cm && this.nav !== 'code') {
@@ -465,11 +471,17 @@ export default {
     }
     }
   }
   }
   .errors {
   .errors {
+    --border: none;
     border-top: 2px solid red;
     border-top: 2px solid red;
-    padding: .5em 1em;
+  }
+  .fatal {
+    background: firebrick;
+    color: white;
   }
   }
   .frozen-note {
   .frozen-note {
     background: var(--bg);
     background: var(--bg);
+  }
+  .shelf {
     padding: .5em 1em;
     padding: .5em 1em;
     border-bottom: var(--border);
     border-bottom: var(--border);
   }
   }