Browse Source

[frontend] Prevent editor from failing to initialize if acePredict throws an error

Johan Åhlén 4 years ago
parent
commit
ca0630c62d

+ 6 - 1
desktop/core/src/desktop/js/apps/editor/components/aceEditor/AceEditor.vue

@@ -516,7 +516,12 @@
         };
 
         if ((<hueWindow>window).ENABLE_PREDICT) {
-          attachPredictTypeahead(editor, executor.value.connector(), sqlAnalyzerProvider.value);
+          try {
+            attachPredictTypeahead(editor, executor.value.connector(), sqlAnalyzerProvider.value);
+          } catch (e) {
+            console.warn('Failed attaching predict typeahead...');
+            console.error(e);
+          }
         }
 
         let placeholderVisible = false;

+ 1 - 1
desktop/core/src/desktop/js/apps/editor/components/aceEditor/acePredict.ts

@@ -28,7 +28,7 @@ type ActivePredict = { text: string; element: HTMLElement };
 export const attachPredictTypeahead = (
   editor: Ace.Editor,
   connector: Connector,
-  sqlAnalyzerProvider: SqlAnalyzerProvider
+  sqlAnalyzerProvider?: SqlAnalyzerProvider
 ): Disposable => {
   if (!sqlAnalyzerProvider) {
     return { dispose: noop };

+ 1 - 1
desktop/core/src/desktop/js/apps/editor/components/aceEditor/autocomplete/SqlAutocompleter.ts

@@ -14,7 +14,6 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-import { SqlAnalyzerProvider } from '../../../../../catalog/analyzer/types';
 import {
   ACTIVE_STATEMENT_CHANGED_EVENT,
   GET_ACTIVE_LOCATIONS_EVENT,
@@ -22,6 +21,7 @@ import {
 } from '../AceLocationHandler';
 import { ActiveStatementChangedEventDetails } from '../types';
 import Executor from 'apps/editor/execution/executor';
+import { SqlAnalyzerProvider } from 'catalog/analyzer/types';
 import SubscriptionTracker, { Disposable } from 'components/utils/SubscriptionTracker';
 import { Ace } from 'ext/ace';
 import { ParsedSqlStatement } from 'parse/sqlStatementsParser';