@@ -25,7 +25,6 @@ import { delay } from "awaiting";
2525import * as CodeMirror from "codemirror" ;
2626import { List , Map , fromJS , Set as iSet } from "immutable" ;
2727import { debounce } from "lodash" ;
28-
2928import {
3029 Actions as BaseActions ,
3130 Rendered ,
@@ -74,6 +73,7 @@ import {
7473 history_path ,
7574 len ,
7675 uuid ,
76+ path_split ,
7777} from "@cocalc/util/misc" ;
7878import { reuseInFlight } from "@cocalc/util/reuse-in-flight" ;
7979import { set_account_table } from "../../account/util" ;
@@ -111,6 +111,7 @@ import { test_line } from "./simulate_typing";
111111import { misspelled_words } from "./spell-check" ;
112112import { log_opened_time } from "@cocalc/frontend/project/open-file" ;
113113import { ensure_project_running } from "@cocalc/frontend/project/project-start-warning" ;
114+ import { alert_message } from "@cocalc/frontend/alerts" ;
114115
115116interface gutterMarkerParams {
116117 line : number ;
@@ -1238,7 +1239,7 @@ export class Actions<
12381239 // several other formatting actions.
12391240 // Doing this automatically is fraught with error, since cursors aren't precise...
12401241 if ( explicit ) {
1241- if ( ! await this . ensureProjectIsRunning ( `save ${ this . path } to disk` ) ) {
1242+ if ( ! ( await this . ensureProjectIsRunning ( `save ${ this . path } to disk` ) ) ) {
12421243 return ;
12431244 }
12441245 const account : any = this . redux . getStore ( "account" ) ;
@@ -1916,31 +1917,30 @@ export class Actions<
19161917 }
19171918 }
19181919
1919- // big scary error shown at top
1920- public set_error (
1921- error ?: object | string ,
1922- style ?: ErrorStyles ,
1923- _id ?: string , // id - not currently used, but would be for frame-specific error.
1924- ) : void {
1920+ private formatError = ( error ?: object | string ) : string | undefined => {
19251921 if ( error === undefined ) {
1926- this . setState ( { error } ) ;
1927- } else {
1928- if ( typeof error === "object" ) {
1929- const e = ( error as any ) . message ;
1930- if ( e === undefined ) {
1931- let e = JSON . stringify ( error ) ;
1932- if ( e === "{}" ) {
1933- e = `${ error } ` ;
1934- }
1935- }
1936- if ( typeof e != "string" ) throw Error ( "bug" ) ; // make typescript happy
1937- error = e ;
1938- }
1939- if ( IS_TIMEOUT_CALLING_PROJECT ( error ) ) {
1940- error = TIMEOUT_CALLING_PROJECT_MSG ;
1922+ return "" ;
1923+ }
1924+ if ( IS_TIMEOUT_CALLING_PROJECT ( error ) ) {
1925+ return TIMEOUT_CALLING_PROJECT_MSG ;
1926+ }
1927+ if ( typeof error == "string" ) {
1928+ return error ;
1929+ }
1930+ const e = ( error as any ) . message ;
1931+ if ( e === undefined ) {
1932+ let e = JSON . stringify ( error ) ;
1933+ if ( e === "{}" ) {
1934+ e = `${ error } ` ;
19411935 }
1942- this . setState ( { error } ) ;
19431936 }
1937+ return e ;
1938+ } ;
1939+
1940+ // big scary error shown at top
1941+ topError ( error ?: object | string , style ?: ErrorStyles ) : void {
1942+ const e = this . formatError ( error ) ;
1943+ this . setState ( { error : e } ) ;
19441944
19451945 switch ( style ) {
19461946 case "monospace" :
@@ -1951,6 +1951,31 @@ export class Actions<
19511951 }
19521952 }
19531953
1954+ set_error ( error ?: object | string , _style ?: ErrorStyles ) : void {
1955+ // show the error at the a toast if this path is the focused one; otherwise,
1956+ // do not show the error at all. We have shown a lot of useless errors
1957+ // and now we will show less, and in a minimally harmful way.
1958+ if ( this . redux . getStore ( "page" ) . get ( "active_top_tab" ) != this . project_id ) {
1959+ return ;
1960+ }
1961+ if (
1962+ ! this . redux
1963+ . getProjectStore ( this . project_id )
1964+ . get ( "active_project_tab" )
1965+ . includes ( this . path )
1966+ ) {
1967+ return ;
1968+ }
1969+ const e = this . formatError ( error ) ;
1970+ if ( e ) {
1971+ alert_message ( {
1972+ type : "error" ,
1973+ title : path_split ( this . path ) . tail ,
1974+ message : e ,
1975+ } ) ;
1976+ }
1977+ }
1978+
19541979 // status - little status message shown at bottom.
19551980 // timeout -- if status message hasn't changed after
19561981 // this long, then blank it.
0 commit comments