@@ -25,7 +25,6 @@ import { delay } from "awaiting";
25
25
import * as CodeMirror from "codemirror" ;
26
26
import { List , Map , fromJS , Set as iSet } from "immutable" ;
27
27
import { debounce } from "lodash" ;
28
-
29
28
import {
30
29
Actions as BaseActions ,
31
30
Rendered ,
@@ -74,6 +73,7 @@ import {
74
73
history_path ,
75
74
len ,
76
75
uuid ,
76
+ path_split ,
77
77
} from "@cocalc/util/misc" ;
78
78
import { reuseInFlight } from "@cocalc/util/reuse-in-flight" ;
79
79
import { set_account_table } from "../../account/util" ;
@@ -111,6 +111,7 @@ import { test_line } from "./simulate_typing";
111
111
import { misspelled_words } from "./spell-check" ;
112
112
import { log_opened_time } from "@cocalc/frontend/project/open-file" ;
113
113
import { ensure_project_running } from "@cocalc/frontend/project/project-start-warning" ;
114
+ import { alert_message } from "@cocalc/frontend/alerts" ;
114
115
115
116
interface gutterMarkerParams {
116
117
line : number ;
@@ -1238,7 +1239,7 @@ export class Actions<
1238
1239
// several other formatting actions.
1239
1240
// Doing this automatically is fraught with error, since cursors aren't precise...
1240
1241
if ( explicit ) {
1241
- if ( ! await this . ensureProjectIsRunning ( `save ${ this . path } to disk` ) ) {
1242
+ if ( ! ( await this . ensureProjectIsRunning ( `save ${ this . path } to disk` ) ) ) {
1242
1243
return ;
1243
1244
}
1244
1245
const account : any = this . redux . getStore ( "account" ) ;
@@ -1916,31 +1917,30 @@ export class Actions<
1916
1917
}
1917
1918
}
1918
1919
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 => {
1925
1921
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 } ` ;
1941
1935
}
1942
- this . setState ( { error } ) ;
1943
1936
}
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 } ) ;
1944
1944
1945
1945
switch ( style ) {
1946
1946
case "monospace" :
@@ -1951,6 +1951,31 @@ export class Actions<
1951
1951
}
1952
1952
}
1953
1953
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
+
1954
1979
// status - little status message shown at bottom.
1955
1980
// timeout -- if status message hasn't changed after
1956
1981
// this long, then blank it.
0 commit comments