Skip to content

Commit 8c50882

Browse files
committed
show file errors in toast
1 parent 2b81c52 commit 8c50882

File tree

2 files changed

+50
-25
lines changed

2 files changed

+50
-25
lines changed

src/packages/frontend/frame-editors/code-editor/actions.ts

Lines changed: 49 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import { delay } from "awaiting";
2525
import * as CodeMirror from "codemirror";
2626
import { List, Map, fromJS, Set as iSet } from "immutable";
2727
import { debounce } from "lodash";
28-
2928
import {
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";
7878
import { reuseInFlight } from "@cocalc/util/reuse-in-flight";
7979
import { set_account_table } from "../../account/util";
@@ -111,6 +111,7 @@ import { test_line } from "./simulate_typing";
111111
import { misspelled_words } from "./spell-check";
112112
import { log_opened_time } from "@cocalc/frontend/project/open-file";
113113
import { ensure_project_running } from "@cocalc/frontend/project/project-start-warning";
114+
import { alert_message } from "@cocalc/frontend/alerts";
114115

115116
interface 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.

src/packages/frontend/frame-editors/jupyter-editor/cell-notebook/actions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -803,7 +803,7 @@ export class NotebookFrameActions {
803803
}
804804

805805
public set_error(error: string): void {
806-
this.frame_tree_actions.set_error(error, undefined, this.frame_id);
806+
this.frame_tree_actions.set_error(error);
807807
}
808808

809809
public async command(name: string): Promise<void> {

0 commit comments

Comments
 (0)